CSAT Tracker

Asked at Decagon· Screen

Reported by the problem's creator, not verified

Import another question

Customer satisfaction (CSAT) is scored per conversation as an integer from 1 to 5. Build CSATTracker, which keeps scores from a rolling time window and reports their average.

A tracker is created with window_size. At time t, a record is in the window if its timestamp is at least t - window_size; older records are dropped and never come back. The timestamp and current_time values arrive in non-decreasing order, and several records may share a timestamp.

Examples

  1. Example 1

    Input: init = [3], operations = [["record",["conv0",1,1]],["record",["conv1",5,2]],["get_average",[3]],["record",["conv2",4,3]],["get_average",[4]],["record",["conv3",3,4]],["get_average",[4]],["record",["conv4",1,5]],["get_average",[5]]]

    Output: [null,null,3,null,3.33,null,3.25,null,3.25]

    Explanation: At time 3, the cutoff is 0, so scores 1 and 5 remain and average 3.0. At time 4, the cutoff is 1; the scores 1, 5, and 4 average 3.33, and adding 3 makes the average 3.25. Recording at time 5 drops the score at timestamp 1 because 1 < 2, leaving 5, 4, 3, and 1.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.