twitter 电面

Given 2 methods and an enum,

  • recordTweet(String tweetName, long time)
  • long[] getTweetCountsPerFrequency(Frequency freq, String tweetName, long startTime, long endTime)
  • enum Frequency {MINUTE, HOUR, DAY}

recordTweet("tweet1", 3498264982l (time in millis)) method is called multiple times for different tweetNames and times that records the time at which the tweet occurred.

For example if the tweetName tweet1 occurs five times in last 2 hours from current time (3 times in first hour and 2 times in second). then the result should be following:

  • getTweetCountsPerFrequency(HOUR, "tweet1", <currentTime-60 mins>, <currentTIme>) should return [3]
  • getTweetCountsPerFrequency(HOUR, "tweet1", <currentTime-120 mins>, <currentTime>) should return [3, 2]
  • getTweetCountsPerFrequency(HOUR, "tweet1", <currentTime-120 mins>, <currentTime - 60>) should return [2]
  • getTweetCountsPerFrequency(DAY, "tweet1", <currentTime - 24 hours>, <currentTime>) should return [5]