Write a program to check whether a given string is a palindrome or not

1 Answers
Answered by suresh

Check if a String is a Palindrome - Interview Question

Palindrome Check Program

To check if a given string is a palindrome or not, you can use the following algorithm:

  1. Declare a function that takes a string as input.
  2. Reverse the input string.
  3. Compare the input string with its reversed version.
  4. If they are the same, the input string is a palindrome.
  5. Return true if it is a palindrome, false otherwise.

Here is a sample implementation in Python:

def is_palindrome(s):
    return s == s[::-1]

input_string = "madam"
if is_palindrome(input_string):
    print(f"{input_string} is a palindrome")
else:
    print(f"{input_string} is not a palindrome")

With this algorithm, you can easily determine if a given string is a palindrome.

Answer for Question: Write a program to check whether a given string is a palindrome or not