Top K Escalation Reasons in a Rolling Time Window
Last updated: November 29, 2026
Quick Overview
Given escalation events (timestamp, reason) from conversations handed to human agents, return the k most frequent reasons in the window (now - window, now], breaking ties alphabetically.
Sierra
November 29, 20260
0
0 solved
Given escalation events (timestamp, reason) from conversations handed to human agents, return the k most frequent reasons in the window (now - window, now], breaking ties alphabetically.
Sierra customers watch why conversations escalate to humans, since every escalation is a missed resolution. This is a short screening problem that checks counting, top-k selection, and precise window boundaries.
What the Interviewer Expects
- Filter events to the window with correct open and closed ends
- Count with a hash map
- Use a heap or sort with the key (-count, reason)
- Return fewer than k results when fewer reasons exist
- State time complexity in terms of events and distinct reasons
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you answer this query every minute on a live stream without rescanning?
- How would you do approximate top-k with bounded memory?
- How would you break this down per customer brand?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Window is (now - window, now], default one day in seconds. Output is a list of reason strings, most frequent first, ties alphabetical. If there are fewer than k distinct reasons, return all of them....
High-Level Design
Count reasons that fall in the window, then select the k smallest by the key (-count, reason). heapq.nsmallest keeps a heap of size k, which beats a full sort when there are many distinct reasons....