PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Decagon

Implement CSAT tracking and call timing

Last updated: Mar 29, 2026

Quick Overview

This question evaluates skills in designing efficient streaming/rolling-window data structures and stateful updates for real-time metrics, alongside parsing and simulating nested function call logs to compute exclusive runtimes.

  • medium
  • Decagon
  • Coding & Algorithms
  • Software Engineer

Implement CSAT tracking and call timing

Company: Decagon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You were asked to solve two coding problems. ### Problem 1: Implement a rolling CSAT tracker Implement a class `CSATTracker` for customer-satisfaction scores. Each recorded score: - belongs to a unique `conversation_id` - is an integer from 1 to 5 - has an integer timestamp The tracker uses a rolling window of size `window_size`. A record is active at time `t` if `record_timestamp >= t - window_size`. Implement: 1. `__init__(window_size: int)` 2. `record(conversation_id: str, score: int, timestamp: int) -> None` - Insert the score. - After insertion, evict any records that are no longer in the active window relative to `timestamp`. 3. `get_average(current_time: int) -> Optional[float]` - Before computing the result, evict any records older than the active window relative to `current_time`. - Return the average active score rounded to 2 decimal places. - Return `None` if there are no active records. 4. `update(conversation_id: str, score: int) -> None` - Update the score for an existing active conversation. - If that conversation has already been evicted, do nothing. - Updating a score must not change its timestamp or its position in eviction order. Assumptions: - `conversation_id` values passed to `record` are unique. - Calls to `record` and `get_average` occur in non-decreasing timestamp order. - The goal is to support these operations efficiently without scanning all stored records on every call. ### Problem 2: Compute exclusive runtime from nested call logs A single-threaded CPU runs `n` functions identified by IDs `0` to `n - 1`. You are given a list of execution logs sorted by timestamp. Each log has the form `function_id:start:timestamp` or `function_id:end:timestamp`. Rules: - A function may call another function, which pauses the currently running one. - Functions may be nested multiple levels deep. - An `end` event at time `t` means the function finishes at the end of time unit `t`, so that unit counts toward the function's runtime. Return an array `answer` where `answer[i]` is the exclusive execution time of function `i`, excluding time spent in any child calls. You may assume the logs are valid and represent a properly nested execution trace.

Quick Answer: This question evaluates skills in designing efficient streaming/rolling-window data structures and stateful updates for real-time metrics, alongside parsing and simulating nested function call logs to compute exclusive runtimes.

Related Interview Questions

  • Implement a Recipe Cart - Decagon (medium)
  • Implement a CSAT Sliding Window Tracker - Decagon (easy)
  • Enumerate 4x4 Tic-Tac-Toe Games - Decagon (medium)
  • Design rolling-window conversation score tracker - Decagon (easy)
  • Compute exclusive CPU time from nested logs - Decagon (medium)
Decagon logo
Decagon
Jan 11, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
10
0
Loading...

You were asked to solve two coding problems.

Problem 1: Implement a rolling CSAT tracker

Implement a class CSATTracker for customer-satisfaction scores.

Each recorded score:

  • belongs to a unique conversation_id
  • is an integer from 1 to 5
  • has an integer timestamp

The tracker uses a rolling window of size window_size. A record is active at time t if record_timestamp >= t - window_size.

Implement:

  1. __init__(window_size: int)
  2. record(conversation_id: str, score: int, timestamp: int) -> None
    • Insert the score.
    • After insertion, evict any records that are no longer in the active window relative to timestamp .
  3. get_average(current_time: int) -> Optional[float]
    • Before computing the result, evict any records older than the active window relative to current_time .
    • Return the average active score rounded to 2 decimal places.
    • Return None if there are no active records.
  4. update(conversation_id: str, score: int) -> None
    • Update the score for an existing active conversation.
    • If that conversation has already been evicted, do nothing.
    • Updating a score must not change its timestamp or its position in eviction order.

Assumptions:

  • conversation_id values passed to record are unique.
  • Calls to record and get_average occur in non-decreasing timestamp order.
  • The goal is to support these operations efficiently without scanning all stored records on every call.

Problem 2: Compute exclusive runtime from nested call logs

A single-threaded CPU runs n functions identified by IDs 0 to n - 1. You are given a list of execution logs sorted by timestamp. Each log has the form function_id:start:timestamp or function_id:end:timestamp.

Rules:

  • A function may call another function, which pauses the currently running one.
  • Functions may be nested multiple levels deep.
  • An end event at time t means the function finishes at the end of time unit t , so that unit counts toward the function's runtime.

Return an array answer where answer[i] is the exclusive execution time of function i, excluding time spent in any child calls.

You may assume the logs are valid and represent a properly nested execution trace.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Decagon•More Software Engineer•Decagon Software Engineer•Decagon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.