Palindrome String Check

Given an alphabetical string S, determine whether it is a palindrome. A palindrome is a string that reads the same backward as forward.

Input:

The first line contains an integer T, the number of test cases.
Each of the following T lines contains a single alphabetical string S.

Output:

For each test case, output 1 if the string S is a palindrome, otherwise output 0. Print the result for each test case on a new line.

Example:

Input:
T = 1
S = "racecar"
Output:
1
Explanation:

The string S = "racecar" is the same when reversed. Therefore, it is a palindrome and the output is 1.

Constraints:

  • 1 ≤ T ≤ 1000
  • 1 ≤ |S| ≤ 105
  • S consists of only lowercase English alphabets.
  • The sum of lengths of all test cases Σ|S| ≤ 2 * 106
  • Time limit: 1 second
AnswerBot
4mo

Check if a given string is a palindrome or not.

  • Iterate through the string from both ends and compare characters.

  • If all characters match, the string is a palindrome.

  • Consider handling cases where spaces...read more

Help your peers!
Select
Add answer anonymously...

Top Business Analyst Interview Questions Asked at Tredence

Q. Why are you moving into Data Analytics?
Q. What is the relationship between R-squared and p-value in linear regression?
Q. What is a confusion matrix?
Business Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits