Tweet Counts Per Frequency

Medium Intervals Binary search Ordered set

Problem

Record tweet times by name, then answer how many tweets of a given name fall into each minute, hour or day chunk of a closed time range [startTime, endTime].

Original: LeetCode 1348: Tweet Counts Per Frequency.

Examples

Example 1

Input`TweetCounts: recordTweet("tweet3", 0), recordTweet("tweet3", 60), recordTweet("tweet3", 10), getTweetCountsPerFrequency("minute", "tweet3", 0, 59), getTweetCountsPerFrequency("minute", "tweet3", 0, 60), recordTweet("tweet3", 120), getTweetCountsPerFrequency("hour", "tweet3", 0, 210)`
Output`[null, null, null, [2], [2, 1], null, [4]]`

Constraints

  • 0 <= time, startTime, endTime <= 10^9
  • 0 <= endTime - startTime <= 10^4
  • There will be at most 10^4 calls in total to recordTweet and getTweetCountsPerFrequency.

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (1)
  1. LeetCode 1348: Tweet Counts Per Frequencyleetcode.com