Help about an algorithm solution

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.

Comments (2)