You are getting stream of data which is stored by calling the function NewData.
void NewData(int time, String key, int value) {
// code which takes the input and stores in some data structure
}And then you call top3 which returns the top 3 keys in the last 10 units of time.
List<String, Integer> top3(int t) {
// returns the top 3 keys from time 't-9' to time 't' inclusive
}Implement these two functions. How will you store the data to optimize getting the data?
example ->
NewData(0, “a”, 1)
NewData(0, “a”, 2) => so after this, key ‘a’ has value 3 at time 0
NewData(0, “b”, 5)
NewData(1, “c”, 6)
NewData(2, “d”, 3)
NewData(3, “d”, 7)
NewData(4, “d”, 1)
NewData(4, “a”, 2)
NewData(5, “b”, 4)
NewData(5, “e”, 5)
NewData(5, “e”, 6)
NewData(5, “d”, 4)
NewData(6, “a”, 2)
NewData(6, “c”, 1)
.
.
.
.
NewData(13, “c”, 5)
top3(13) => it should return aggregated top 3 keys from time 4 to time 13 like
[(‘d’, 12), (‘e’, 11), (‘c’, 6)]
Comments (5)


