Maintain k-th largest in a stream
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates understanding of data structures and streaming algorithms for maintaining k-th order statistics under dynamic inserts, emphasizing time-space trade-offs and correct handling of duplicates.
Constraints
- Inputs are provided as Python literals matching the function signature.
- Return a deterministic exact-match result.
Examples
Input: (3, [4,5,8,2], [3,5,10,9,4])
Expected Output: [4, 5, 5, 8, 8]
Explanation: Classic sequence.
Input: (1, [], [2,1])
Expected Output: [2, 2]
Explanation: Largest so far.
Input: (3, [], [1,2])
Expected Output: [None, None]
Explanation: Fewer than k elements.
Hints
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.