saket9450's blog

By saket9450, history, 11 years ago, In English

hacker rank problem can any one please give me some hint to solve this problem

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
11 years ago, hide # |
Rev. 2  
Vote: I like it +3 Vote: I do not like it

If the input is small enough (constraints aren't specified), you can just append another copy of S to the back of it and check all substrings of length |S|. If you find a palindrome at position i (counting from 0), then the required number of shifts is min(|S| - i, i). Output the minimum among all of them.