Katkat

Find Top Hashtags

F5NetworksSoftware Engineer · Online Assessment

Last 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 the i-th tweet as a string
  • timestamps[i]: the publish time of the i-th tweet as an integer

You are also given two integers:

  • currentTime
  • timeWindow

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.