Limits 1s, 256 MB

Finally, MJ and Peter Parker have time for each other. They are running good times. It all begins with a cute little interaction between MJ and Peter; they are on the roof together while MJ reads to Peter about his supposed "powers," including his ability to learn anything quickly. Their joy seems short-lived because Peter reveals that he has a training class with Reeba.

MJ asks Peter about his last training class topic. The last class was about string palindromes. Alas!!! Suddenly Peter remembers that Reeba gave a task to Peter in the previous class and becomes nervous. After seeing Peter's nervousness, MJ tells Peter to seek your help. Peter asks for your help to solve the problem. The problem is -  “You will be given a string S, size of N, and you have to find a  minimum length (length>1) palindrome string from the given string.”

In case you don’t remember what a palindrome string is -

"A palindrome is a string that reads the same backwards as forwards."

For example, the strings "dad", "mom", "wow" and "acabaca" are palindrome strings. But the strings "abc", "aabbdd" and "abracadabra" are not palindromes.

In this problem, you have to find a minimum length (length>1) palindrome from a given string and its starting and ending position. For example - in the string “aabccb”, there are three palindrome strings, “aa”, “bccb” and “cc” - where “aa” and “cc” have minimum length but “aa” has minimum starting and ending position (1 and 2).


The first line of input contains a single integer N, the length of the input string.  The second line of input contains a string S consisting of lowercase English letters length of N.

2N10002 \leq N \leq 1000


If it’s impossible to extract a palindrome from the given string, print ”No”. Otherwise, print “Yes” in the first line; in the second line, print the starting and ending position (1 base index) of the minimum length palindrome. If there exist multiple answers, you have to print the palindrome with a minimum starting position. See the sample test and explanation for better understanding.


2 3

“abbacc” in this string there are three palindromes - “abba”, “bb” and “cc”. From this three palindrome strings “bb” and “cc”  have minimum length. But “bb”  has a minimum starting position.

1 2

Notes: Be careful about the newline(‘\n’) at the end.


Login to submit.


49% Solution Ratio
abu_fayeemEarliest, Mar '22
sodiumfis_hFastest, 0.0s
abu_fayeemLightest, 131 kB
mdnakib_025Shortest, 410B
Toph uses cookies. By continuing you agree to our Cookie Policy.