• + 1 comment

    Hi,

    Not sure if I understand the following solution correctly (it passed the test case) but seems to be wrong to me. https://github.com/wangyongliang/Algorithm/blob/master/hackerrank/Strings/Square%20Subsequences/main.cc and https://www.quora.com/What-are-some-suggestions-on-how-to-solve-this-counting-problem

    Basically, if string is devided into 2 substrings: first from index 0 -> index t-1 (t>=1); second from index t -> N-1 (N is length of string); then it counts number of common subsequence of 2 strings (classic problem) and adding this to the final result (t will be in the loop from 1 -> N-1).

    The problem is that some square subsequence will be counted >= twice. For example, if string is "abcdab"; t=2 -> ab is common subsequence of both substring "ab" and "cdab" (add to final result 1); but t=3; "ab" still common subsequence of both "abc" and "dab". In other words, the square substring "abab" is count twice in the solution?

    Am I misunderstanding somethings or there is problem with the question itself?

    Thanks!