1

Program has for input 1 or more periods of both sequences. How to test whether these sequences are the same with the least number of comparisons.

What's the best way to do it?

Serillan
  • 227
  • 2
  • 8

1 Answers1

2

Find the smallest period of the two input strings, see for example this question and this question which describe a solution using the Knuth-Morris-Pratt algorithm. Once you've found the strings' smallest periods then it's trivial to compare them.

Community
  • 1
  • 1
Zim-Zam O'Pootertoot
  • 17,888
  • 4
  • 41
  • 69