FastPrepFastPrep
Problem Brief

Chat Event Counts in Recent Window

FULLTIMEPHONE SCREEN

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 that userId had an event in chatId at timestamp.
  • 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 than timestamp - 15 minutes.

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 Description

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.

1Example 1

Input
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"
Output
["2","1","2","1"]
Explanation

At timestamp 16, the event at minute 0 is older than 15 minutes and is not counted.

Constraints

Limits and guarantees your solution can rely on.

Timestamps are integer minutes and commands are processed in input order.

Counts are keyed by both user id and chat id.

public String[] solveChatEventCounts(String input) {
    // write your code here
}
Input

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"

Output

["2", "1", "2", "1"]

Sign in to submit your solution.