2
Map<String, List<Integer>> map;8
public void recordTweet(String tweetName, int time) {9
map.computeIfAbsent(tweetName, v -> new ArrayList<>()).add(time);12
public List<Integer> getTweetCountsPerFrequency(13
String freq, String tweetName, int startTime, int endTime) {14
List<Integer> res = new ArrayList<>();15
if (map.containsKey(tweetName)) {16
Collections.sort(map.get(tweetName));17
while (startTime <= endTime) {18
int interval = Freq.valueOf(freq).getVal();20
Math.min(startTime + interval - 1, endTime); // need this to handle the last interval21
res.add(getFreq(map.get(tweetName), startTime, end));23
end + 1; // ex: for minute, the interval is 60 so our end is 59. The next startTime is30
public int getFreq(List<Integer> list, int start, int end) {31
int st = Collections.binarySearch(list, start);33
st = (st + 1) * -1; // our exact start time might not be in the list, to get the 1st timestamp36
int en = Collections.binarySearch(list, end);40
* -1; // our exact end time might not be in the list, to get the last timestamp just44
return en - st + 1; // the freq count52
Map<Freq, Integer> map = new HashMap<>();64
* Your TweetCounts object will be instantiated and called as such: TweetCounts obj = new65
* TweetCounts(); obj.recordTweet(tweetName,time); List<Integer> param_2 =66
* obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);