FastPrepChat Event Counts in Recent Window

Chat Event Counts in Recent Window

OpenAI logoOpenAI● MediumFULLTIMEPHONE SCREEN
Learn

Problem 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 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

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.

More OpenAI problems

See OpenAI hiring insights
public String[] solveChatEventCounts(String input) {
    // write your code here
}
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"
expected["2", "1", "2", "1"]
Checking account…