FastPrepRolling CSAT Tracker

Rolling CSAT Tracker

Decagon logoDecagon● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Process timestamped customer-satisfaction operations in nondecreasing time order. ADD t score records a score from 1 through 5. QUERY t asks for the average of scores whose timestamps lie in [t-windowSize+1, t].

Return one reduced sum/count fraction per query, or EMPTY when the active window has no scores.

Function

rollingCsat(operations: String[], windowSize: int) → String[]

Examples

Example 1

operations = ["ADD 1 5","ADD 3 3","QUERY 3","QUERY 6"]windowSize = 5return = ["4/1","3/1"]

At time 3 both scores are active; at time 6 only the score from time 3 remains.

Example 2

operations = ["QUERY 2","ADD 2 4","QUERY 2"]windowSize = 3return = ["EMPTY","4/1"]

The tracker distinguishes an empty window from a numeric average.

Example 3

operations = ["ADD 0 1","ADD 1 2","ADD 2 5","QUERY 2"]windowSize = 3return = ["8/3"]

The exact rational average is returned without floating-point rounding.

Constraints

  • 1 <= operations.length <= 2 * 10^5.
  • 1 <= windowSize <= 10^9.
  • Timestamps are nonnegative and nondecreasing; scores are integers from 1 through 5.

More Decagon problems

See Decagon hiring insights
public String[] rollingCsat(String[] operations, int windowSize) {
    // Write your solution here.
}
operations["ADD 1 5","ADD 3 3","QUERY 3","QUERY 6"]
windowSize5
expected["4/1", "3/1"]
Checking account…