Palindrome String

Practice this coding question on Coding Gurukul.

Problem statement

A badge designer wants to identify labels that look the same when their letter order is read from either end. Such labels can be used in a reversible-word display. Your task Determine whether the string is a palindrome. Important details Compare characters exactly as written. Uppercase and lowercase letters are different, and no characters should be removed or rearranged. A string with one character is a palindrome. You can compare matching characters from both ends in O(n) time and O(1) auxiliary space. Worked example The label level reads the same in both directions, so print 1. The label Level fails because its uppercase L differs from the final lowercase l, so print 0.

Input format

One nonempty string s.

Output format

Print 1 for a palindrome, otherwise 0.

Constraints

1 <= length(s) <= 100000; s contains English letters.

Sample input

level

Sample output

1

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…