Palindrome Check via Slicing

Easy ⏱ 8 min 84% acceptance ★★★★★ 4.8
Write is_palindrome(s) that returns True if s reads the same forwards and backwards, comparing it directly against its reversed slice. Treat the comparison as case-sensitive and do not strip any characters.

Examples

Example 1
Input
s = 'level'
Output
True
Explanation

'level' reversed is still 'level'.

Example 2
Input
s = 'Level'
Output
False
Explanation

Case-sensitive: 'Level' reversed is 'leveL', which differs.

Constraints

  • 0 <= len(s) <= 10^4
  • Comparison is case-sensitive.

Topics

StringsSlicing

Companies

GoogleWiproCognizant

Hints

Hint 1

Compare `s` to `s[::-1]`.

Hint 2

An empty string is trivially a palindrome.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.