We are given 2 lines (DNA Sequences) of equal length of upto 105 characters consisting of alphabets A, T, G, C only.
We have to find the ith cyclic shift of one string for which maximum characters are matched between the two strings.
We have to do it in better than O(n2) obviously. Any hints?
Suppose that strings are composed only by 0 and 1.. If the text is s with length(s) = n and the pattern is t with length(t) = m, reverse the pattern first, and then for each string build the polynomial P(w) = w[0] + w[1] × x + ... + w[length(w) - 1] × xlength(w) - 1. The coefficient of the term i + m - 1 in P(s + s) × P(rev(t)) give you the matches of the i - th cyclic shift of s with t.. For solving the original problem calculate the answer for each different letters and add up the result for obtain the answer for the original.