Skip to content
CodeKruPro

Check whether a string is a palindrome

Coding problemEasyAsked in: Accenture, Capgemini, Wipro

Given a string s, return true if it reads the same from both ends (this is called a palindrome), and false otherwise.

Ignore upper and lower case: "Racecar" is a palindrome. Every other character counts as it is, including spaces and digits, so a number written as text such as "12321" works the same way. An empty string is a palindrome.

Examples

Example 1
Input: s = "Racecar"
Output: true
Example 2
Input: s = "12321"
Output: true
Example 3
Input: s = "abca"
Output: false
The second character b does not match the second-to-last character c.

Constraints

  • The length of s is between 0 and 100,001
  • s holds printable ASCII characters only

Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.

Run your code to see the results here.

to answer and keep your progress. Reading is free for everyone.