Find Top Hashtags
F5NetworksSoftware Engineer · Online AssessmentLast updated
This question evaluates string parsing and tokenization, frequency counting of elements, time-window filtering of events, and the ability to sort results with deterministic tie-breaking rules.
You are given two arrays of length n:
tweets[i]: the content of thei-th tweet as a stringtimestamps[i]: the publish time of thei-th tweet as an integer
You are also given two integers:
currentTimetimeWindow
Consider only tweets whose timestamp falls within the inclusive time interval:
[currentTime - timeWindow, currentTime]
A hashtag is any token in a tweet that starts with #. Count hashtag popularity by the number of times each hashtag appears in the tweets within the time window.
Return the most popular at most 3 hashtags. Sort hashtags by descending count. If two hashtags have the same count, sort them lexicographically ascending. If fewer than 3 hashtags appear in the time window, return all of them.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.