Company: Paytm
Question:
Output:
Print "Yes" if it is a palindrome else "No". (Without the double quotes)
Constraints:
1<=T<=30
1<=N<=100
Example:
Input:
1
4
abba
Question:
Given a string s check if it is palindrome or not.
Input:
The first line contains 'T' denoting the number of test cases. Then follows description of test cases.
Each case begins with a single integer N denoting the length of string. The next line contains the string s.
The first line contains 'T' denoting the number of test cases. Then follows description of test cases.
Each case begins with a single integer N denoting the length of string. The next line contains the string s.
Output:
Print "Yes" if it is a palindrome else "No". (Without the double quotes)
Constraints:
1<=T<=30
1<=N<=100
Example:
Input:
1
4
abba
Output:
Yes
Yes
CODE:
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG {
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
int m =sc.nextInt();
for(int mi=0;mi<m;mi++){
int n=sc.nextInt();
String s1 =sc.next();
// System.out.print(s1+" ");
char [] t1= s1.toCharArray();
int count=0;
for(int i=n-1;i>=0;i--){
if(t1[i]==t1[n-i-1]){
count++;
}
}
if(count>=n/2){
System.out.println("Yes");
}
else{System.out.println("No");}
}
}
}
Execution Time: 0.13
Comments
Post a Comment