Accenture Coding Question | String Palindrome | CodeWindow

String Palindrome

Write a function to find if the given string string is palindrome or not. Return 1 if the input string is a palindrome, else return 0.

Input specification:
Input 1: A string of characters.

Output Specification:
0 or 1 depending on whether the string is a palindrome or not.

Example 1:
Input 1: level

Output: 1
Explanation:
The reverse of string ‘level’ is ‘level’. As they are same hence the string is a palindrome.

Example 2:
Input 1: abcd

Output: 0
Explanation:
The reverse of string ‘abcd’ is ‘dcba’. As they are not the same hence the string is not a palindrome.

Solution in Python 3:

#https://codewindow.in
# Join our Telegram Channel

s=input()

s_rev=list(reversed(s)) #returns a list of the reversed string

revStr=''.join(s_rev) #joins the elements of the reversed list to a string

#print(revStr)

if s==revStr:
    print('1')
else:
    print('0')
    
# Telegram @codewindow

Output:

level
1
abcd
0
Recent Posts

Leave a Comment

Your email address will not be published. Required fields are marked *