I encountered a problem and have tried many solutions, but none have worked. Given an array of numbers [3, 2, 16, 16, 15, 1, 2, 16, 16, 16, 15, 1, 2], I would like to discover the repeated sequence in this array.
The expected output should be [16, 16, 15, 1, 2].
2
Answers
You could take two nested loops and check the first and second same values with an offset for a sequence.
I’ve compared to Nina’s solution. While with small arrays Nina’s solutions wins because there’s nothing to initialize. But with increasing number of elements and repeated parts my algorithm get more faster due the linked list optimization. I even think there’re even some more optimization possible.