Check if a number is palindrome
Given an alphabetical string ‘S’. Determine whether it is palindrome or not. A palindrome is a string that is equal to itself upon reversing it.
For example:
‘S’ = racecar
The reverse of ‘S’ is: racecar
Since ‘S’ is equal to its reverse. So ‘S’ is a palindrome.
Hence output will be 1.
Input Format:
The first line of the input contains a single integer ‘T’ representing the no. of test cases.
The first line of each test case contains a single alphabetical string, ‘S’.
Output Format:
For each test case, print a single integer value 1 if the given string ‘S’ is palindrome and 0 otherwise.
Print a separate line for each test case.
Note
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
Constraints -
1 ≤ T ≤ 1000
1 ≤ |S| ≤ 10^5
S consists of only lowercase english alphabets.
Σ|S| ≤ 2 * 10^6
Time limit: 1 Sec
CodingNinjas
author
2y
One approach could be to first reverse digits of n, then compare the reverse of n with n. If both are same, then return true, else false.
Pseudo code :
reverseDigits(num) { Initialise a variable rev_nu...read more
CodingNinjas
author
2y
1Space Complexity: O(1)Explanation: Time Complexity: O(n)Explanation:
Java (SE 1.8)
Java (SE 1.8)
/*
Time Complexity: O( N ).
Space Complexity: O( 1 ).
Where N is the length of the string.
*/
public class Solution {
p...read more
Help your peers!
Add answer anonymously...
Top Tredence Business Analyst interview questions & answers
Popular interview questions of Business Analyst
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app