Skip to content

Practice Tweet Counts Per Frequency

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1348
LeetCode Problem

Tweet Counts Per Frequency

Problem Statement

TweetCounts records recordTweet(tweetName,time) events in seconds. getTweetCountsPerFrequency(freq,tweetName,startTime,endTime) counts that name's events in successive buckets anchored at startTime, including both query endpoints. Bucket sizes are 60, 3600, or 86400 seconds for minute, hour, or day. The last bucket may be shorter; empty buckets count as zero. Practice approach: Store sorted times per name. For each bucket, subtract lower-bound positions at its start and just beyond its inclusive end. Preserve duplicate timestamps and do not align buckets to clock boundaries. Out-of-order records require ordered insertion or deferred sorting.

Source: Tweet Counts Per Frequency on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["TweetCounts","recordTweet","recordTweet","recordTweet","getTweetCountsPerFrequency","getTweetCountsPerFrequency"]
[[],["a",10],["a",69],["a",70],["minute","a",10,70],["hour","a",10,70]]
Output
[null,null,null,null,[2,1],[3]]
Explanation

Minute buckets are [10,69] and [70,70], whereas the hour query has one shortened bucket.

Constraints

0 <= time, startTime, endTime <= 10^9
0 <= endTime-startTime <= 10^4
At most 10^4 total calls.

Related LeetCode Problems

Practice more problems similar to Tweet Counts Per Frequency.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.