Top 3 Trending Hashtags in a Time Window
You are given two arrays of equal length: tweets and timestamps. The i-th tweet was published at time timestamps[i] and contains text tweets[i].
Within the inclusive interval [currentTime - timeWindow, currentTime], find the top at most three hashtags by total number of occurrences.
A hashtag starts with # and continues through consecutive letters, digits, or underscores. Stop the hashtag when any other character is encountered.
Sort the answer by count descending, then lexicographically ascending for ties. Return each hashtag with its leading #.
Complete the function topTrendingHashtags in the editor below.
topTrendingHashtags has the following parameters:
String[] tweets: the tweet textsint[] timestamps: publish timesint currentTime: the right end of the windowint timeWindow: the window width
Returns
String[]: the top at most three hashtags in ranked order.
1Example 1
The active window is timestamps 2 through 4. #b appears twice and #a appears once.
2Example 2
Both hashtags appear twice, so lexicographical order breaks the tie.
Constraints
Limits and guarantees your solution can rely on.
1 <= tweets.length == timestamps.length <= 2 * 10^50 <= timestamps[i] <= 10^9sum(len(tweets[i])) <= 10^6