As reported: Amazon SDE 1 loop (June 2025), round 1 — one Leadership Principle question and two coding questions; this was the second: the k-th largest element of an infinite stream at any point in time. It also came up in an Amazon SDE intern interview (Bangalore, February 2025, technical interview 2, solved with a min-heap with follow-ups on edge cases) and in an Amazon SDE1 (AUTA) loop (May 2025, round 2, worded as the k-th largest number from index
kton).
Integers arrive one at a time; stream lists them in arrival order. After each arrival, report the k-th largest value among all values seen so far, or -1 if fewer than k values have arrived.
This is LeetCode 703 — Kth Largest Element in a Stream, answered after every arrival.
Example 1
stream = [10,20,11,70,50,40,100,5], k = 3
Output: [-1,-1,10,11,20,40,50,50]
Example 2
stream = [4,2,1,3], k = 2
Output: [-1,2,2,3]
Constraints: 1 ≤ stream.length ≤ 10⁵; 1 ≤ k ≤ 10⁵; 0 ≤ stream[i] ≤ 10⁹.
Clarifications
- Equal values count separately (
[3,3]withk = 2→ the second largest is3).
Code runner format: one JSON value per line, in order: stream, k. Implement kthLargestSoFar(stream, k); the harness prints the answers as a JSON array.