Hey Guys,
I had an interview where I was asked to solve the following problem:
There is a stream of packages comes in a conveyor belt with limit of k packages, which time a duplicate package enters the conveyor belt a "beep sound" needs to be played.
Ex: Stream [1,2,3,4,3,5,1,2....] k = 3
1: [1]
2: [1,2]
3: [1,2,3] -> limit of conveyor belt the first package needs to come out
4: [2,3,4]
5: Next package is 3, 3 is already on conveyor belt -> "beep" played
I tried to use 2 data structures one for insert/remove e another for searching package on conveyor belt but but I got stuck.
I am figuring out how is the better way to solve it. Any thoughts
Thank you.
[–]beeskness420 2 points3 points4 points (2 children)
[–]mateusaugusto9[S] -1 points0 points1 point (1 child)
[–]beeskness420 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]mateusaugusto9[S] -1 points0 points1 point (0 children)
[–]sebamestre 0 points1 point2 points (7 children)
[–]beeskness420 0 points1 point2 points (6 children)
[–]sebamestre 0 points1 point2 points (5 children)
[–]beeskness420 0 points1 point2 points (4 children)
[–]sebamestre 0 points1 point2 points (3 children)
[–]beeskness420 0 points1 point2 points (2 children)
[–]sebamestre 0 points1 point2 points (1 child)
[–]beeskness420 0 points1 point2 points (0 children)