DOUBLE - Editorial

PROBLEM LINKS

Practice
Contest

DIFFICULTY

EASY

EXPLANATION

It was the easiest problem in the set. Actually, I wanted to make a problem that will be solved by very big number of contestants and it seems that I have succeeded :slight_smile:
If N is odd then the answer is N-1, else the answer is N. When we have a palindrome of even length, we can reverse the first N/2 symbols of it to obtain a double string, so the answer for even N is N. It is impossible to make a double string with an odd number of symbols but we can remove the central symbol to obtain an even length palindrome and the answer then is equal to N.

SETTER’S SOLUTION

Can be found here.

TESTER’S SOLUTION

Can be found here.

3 Likes

Cant string having length 1 be a palindrome?
coz i considered string having length 1 as a palindrome and got wrong answer
please do clear my doubts.
Thank you.

Admin, why does this fail?? (Something very basic I’m missing ?)

def main():
	t = int(raw_input())
	for i in xrange(t):
		n = raw_input()
		if n[-1] in '02468':
			print int(n)
		else:
			print (int(n)-1)
if __name__ == "__main__":
	main()

considering the question, if we have input as 4 , the answer stated is 4,
however, lets take an example with string palindrome as “abba”
the double strings formed are

  1. aa
  2. bb
  3. abab
  4. baba
  5. “” (null)
    hence the answer should be 5. If we have to forget the null string , the answer of the input 2 should be 1, but the problem has stated output as 2.
    example : aa
    double string will be “aa” only.
    Please tell me where am i wrong?