亚麻 sde1电面 top products from stream

I recently appeared for Amazon SDE1 onsite interviews got this question “Get Top N product from the stream of data having product name and timestamp in last m minutes” in the third round. Can anyone please help me figure out how to solve this problem?

Example:
Product Timestamp
ID1 10:01
ID1 10:02
ID1 10:03
ID2 10:03
ID3 10:04
ID4 10:05
ID2 10:05
ID1 10:06
ID2 10:06
ID4 10:06

If the current time is 10:10 and m=5 mins then top n=2 products will be ID2 and ID4
Similarly, if current time is 10:10 and m=10 mins then top n=3 products will be ID1, ID2 and ID4.