Skip to content

Check Palindrome

EasyPython 3StringsTwo pointers

Given the string, check if it is a palindrome — i.e. it reads the same left to right and right to left. Return True if it is a palindrome, otherwise return False. Comparison is character-for-character over the whole string (no case-folding or whitespace stripping); the input is a plain string that may be empty.

Examples:
  "aabaa"  -> True   (reversed is "aabaa")
  "abac"   -> False  (reversed is "caba")
  "a"      -> True   (single character)
  ""       -> True   (empty string is trivially a palindrome)
  "xx"     -> True   (reversed is "xx")

Python 3, run in your browser. Run tests runs the problem's own tests with a free account; the AI interviewer reads your code and your runs in a practice interview.

Loading the editor…