Medium · Hash Maps
Find top K tweet words in a recent window
Given tweets that each carry one word and a timestamp, the current time now, a window length and k, return the k most frequent words among tweets with now − window ≤ timestamp ≤ now, ordered by count (highest first) with ties in alphabetical order — or every such word if there are fewer than k.
Examples
Example 1
cat@3 dog@6 cat@7 fox@9 cat@10 dog@12 · now=10, win=5, k=2Output: [cat, dog]
Example 2
hi@2 go@5 hi@6 go@8 · now=8, win=4, k=1Output: [go]
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.