Alternate Palindrome
Description
Given a string of even length , we choose characters alternatively starting from front then back then front and so on and check whether the string so formed is a palindrome or not.
A string is a palindrome if it reads same forwards and backwards.
Note: String contains lowercase English alphabet, and it is 0-index based
e.g.:
"abab", string formed if we choose element at 0th index then last index then 1st and then second last and so on till we exhaust the string.
string formed : "abba", it is a palindrome, so output will be "yes"
Input
Input Format:
First line of input contains the number N , denoting the length of the string
Second line of input contains the string.
Constraints:
1<=N<=500
Output
Output "yes" or "no"
Hint
In Sample 1:
N = 4
String: abab
String formed after choosing characters in alternate way, like we choose , a->b->b->a, Index : 0 then 3 then 1 and finally 2, So the string is "abba", which is a palindrome, so output will be yes
In Sample 2:
N = 5
String: abcdef
String formed after choosing characters in alternate way, like we choose, a->f->b->e->c->d, "afbecd" which is not a palindrome , so output will be no
Answer
Comments
Post a Comment