Not_So_Great's blog

By Not_So_Great, history, 21 month(s) ago, In English

I have solved the easy version of the problem. But I have no idea how to solve this one. Do I require any new algorithms? Can someone please help me solve this problem?

  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?
»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Learn pattern searching algorithms like Z function, KMP, etc. I used Z function to solve this question.

  • »
    »
    21 month(s) ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Can you explain a bit more in detail on how to solve this after learning pattern matching algorithms?

    • »
      »
      »
      21 month(s) ago, hide # ^ |
      Rev. 3  
      Vote: I like it 0 Vote: I do not like it

      The problem after this will turn into "for string $$$s$$$ of length $$$n$$$, find any index $$$i$$$ ($$$2 \le i \le n$$$) such as $$$s(i, n) = s(1, n-i+1)$$$ and $$$i \le n-i+1$$$".

      (Here, $$$s(i, j)$$$ means a contiguous substring of $$$s$$$ from index $$$i$$$ to index $$$j$$$, inclusively).