Implement an expiring counter class
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's competency in implementing a sliding-window expiring counter, testing knowledge of streaming algorithms, data structures for time-series aggregation, amortized time complexity, and memory-efficient design in the Coding & Algorithms domain.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (3, [['inc',1,2], ['inc',2,1], ['get',3], ['get',4]])
Expected Output: [None, None, 3, 1]
Explanation: Inclusive 3-second window.
Input: (2, [['get',0], ['inc',5,4], ['get',6]])
Expected Output: [0, None, 4]
Explanation: Empty then one bucket.
Input: (1, [['inc',1], ['inc',1,3], ['get',1], ['get',2]])
Expected Output: [None, None, 4, 0]
Explanation: Aggregate same-second events.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.