Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find loop/ repetition in a data stream?

I came across an interesting question in an interview. But I couldn't answer it, neither I found it on Google.

Question is as follows:

You are given a data stream. With the help of variable declaration how you can find whether there is any repetition or loop in the data.

Example of the data stream are:

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

How can this problem be solved? Is there any algorithm for such kind of problem?

like image 236
Indzi Avatar asked Jan 28 '23 21:01

Indzi


1 Answers

I think there must two approaches to this problem

1. Longest repeated substring problem

This is well known problem which have solution in linear time. You have to construct suffix tree for your string then analyze it. Please check this article for details

2. Repeated substring problem (any)

You can modify Longest repeated substring to find any repeated substring.

like image 145
Gor Avatar answered Feb 05 '23 20:02

Gor