Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome String Function

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

Your question is Palindrome String Function. 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

An Impossible Foods packaging utility receives a label string and must identify whether the label is a palindrome. Write a function that returns True when the string reads exactly the same from left to right and right to left, and False otherwise.

Characters are case-sensitive, and spaces and punctuation are treated as ordinary characters. Do not modify the input string.

Formal Specification

  • Input: A string s containing zero or more ASCII characters.
  • Output: A Boolean value. Return True if s is a palindrome; otherwise, return False.

Use a two-pointer comparison so the function can stop as soon as a mismatched pair is found.

Constraints

  • 0 <= len(s) <= 10^5
  • s contains only ASCII letters, digits, spaces, or punctuation
  • Comparisons are case-sensitive
  • Spaces and punctuation are significant

Function Signature

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