Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome True or False

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

Your question is Palindrome True or False. 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

As part of validating text produced by Altair HyperWorks, write a function that determines whether a given string is a palindrome. A palindrome reads the same from left to right and right to left.

Comparison is case-sensitive, and every character, including spaces and punctuation, must be considered. Return True when the string is a palindrome and False otherwise. An empty string is considered a palindrome.

Formal Specification

Implement is_palindrome(s), where s is a string. Return a Boolean value:

  1. True if s equals its reverse.
  2. False otherwise.

You should compare characters from both ends toward the center rather than creating a reversed copy of the string.

Constraints

  • 0 <= len(s) <= 10^5
  • s contains printable ASCII characters
  • Comparison is case-sensitive
  • Every character, including spaces and punctuation, must be considered

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