Chat Event Counts in Recent Window
Learn this problemProblem statement
Complete the function below. The function receives the full standard input as a single string and returns the exact standard output lines for a chat-event tracker.
Problem
Implement two operations for tracking chat events:
processEvent(userId, chatId, timestamp): record thatuserIdhad an event inchatIdattimestamp.getCount(userId, chatId, timestamp): return how many events for that exact(userId, chatId)pair occurred in the last 15 minutes, inclusive of the query timestamp and exclusive of events older thantimestamp - 15minutes.
In this command-based version, each line is either EVENT userId chatId timestamp or COUNT userId chatId timestamp. Return one output line for each COUNT command.
Function
solveChatEventCounts(input: String) → String[]Complete solveChatEventCounts. It has one parameter, String input, containing newline-separated commands. Return the stdout payload as an array of lines, without trailing newline characters.
Examples
Example 1
input = "EVENT u1 c1 0\nEVENT u1 c1 10\nEVENT u1 c2 12\nCOUNT u1 c1 14\nCOUNT u1 c1 16\nEVENT u1 c1 20\nCOUNT u1 c1 25\nCOUNT u1 c2 25"return = ["2","1","2","1"]At timestamp 16, the event at minute 0 is older than 15 minutes and is not counted.
Constraints
Timestamps are integer minutes and commands are processed in input order.
Counts are keyed by both user id and chat id.