Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome String Program

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Palindrome String Program. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Creative Synergies Group uses short asset labels in review workflows. Implement a function that determines whether a label is a palindrome.

A palindrome reads the same from left to right and right to left. Compare characters exactly as provided: comparisons are case-sensitive, and spaces or punctuation are treated as ordinary characters.

Formal Specification

Implement is_palindrome(text).

  • Input: text, a string.
  • Output: Return true if text is a palindrome, otherwise return false.

Use a two-pointer approach that compares the first and last remaining characters, then moves inward. Return as soon as a mismatch is found.

Constraints

  • 0 <= len(text) <= 100,000
  • text contains letters, digits, spaces, and punctuation
  • Character comparison is case-sensitive
  • Spaces and punctuation must be compared as ordinary characters

Function Signature

def is_palindrome(text):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output