Tweet Counts Per Frequency
Let’s break down the problem:
- Storing the Tweets: Every time a tweet is recorded, it needs to be stored against its tweetName and the time of tweet.
- Counting the Tweets: Based on the frequency provided, we need to break the time between
startTime
andendTime
into smaller chunks and count the number of tweets in each chunk.
Data Structures
- Use a dictionary called
tweets
, where the key is thetweetName
and the value is a list of all the tweet times for that tweetName.
Method Implementations
- recordTweet: Simply append the time to the list of times for that
tweetName
. - getTweetCountsPerFrequency: First determine the size of each chunk based on the given frequency. Then, for the given tweetName, partition the period between
startTime
andendTime
into chunks of the determined size and count the number of tweets in each chunk.
Let’s implement this:
|
|
This design efficiently stores the tweets and provides quick lookup times to count the tweets in each chunk for the given frequency.