1import bisect234class TweetCounts:56def __init__(self):7self.tweets = {}89def recordTweet(self, tweetName: str, time: int) -> None:10if not tweetName in self.tweets:11self.tweets[tweetName] = []12index = bisect.bisect_left(self.tweets[tweetName], time)13self.tweets[tweetName].insert(index, time)1415def getTweetCountsPerFrequency(16self, freq: str, tweetName: str, startTime: int, endTime: int17) -> List[int]:1819def find(step):20nonlocal tweet21result = []22for i in range(startTime, endTime + 1, step):23result.append(24bisect.bisect_right(tweet, min(endTime, i + step - 1))25- bisect.bisect_left(tweet, i)26)27return result2829tweet = self.tweets[tweetName]30if freq == "minute":31return find(60)32elif freq == "hour":33return find(3600)34else:35return find(86400)