How to find loop / repeat in data stream?

In an interview I met an interesting question. But I could not answer it, and I did not find it on Google.

The question is:

You are provided with a data stream. By declaring a variable, you can find out if the data has a repetition or a loop.

Example data stream:

100100100100
0001000100010001
100100010001
10...0010....010....01(where 0....0 is 0^10^10^10)

How to solve this problem? Is there any algorithm for this kind of problem?

+4
source share
2 answers

I think there should be two approaches to this problem

1. The longest recurring substring problem

, . suffix tree , . ,

2. ()

Longest repeated substring, .

+5

, 100100100100 :

dict["1"]++
dict["10"]++
dict["100"]++
dict["1001"]++

.. . , .. 1 00100100100 :

dict["0"]++
dict["00"]++
dict["001"]++
dict["0010"]++

.

.

, , .

+3

Source: https://habr.com/ru/post/1692030/


All Articles