Example 1
- Input
- ["KthLargest","add","add","add","add","add"]
[[3,[4,5,8,2]],[3],[5],[10],[9],[4]]
- Output
- [null,4,5,5,8,8]
The constructor returns null. Initially the largest three entries are [8,5,4]. After arrivals 3,5,10,9,4, the top-three lists are [8,5,4], [8,5,5], [10,8,5], [10,9,8], [10,9,8], giving cutoffs 4,5,5,8,8. Both copies of 5 count.
Example 2
- Input
- ["KthLargest","add","add","add"]
[[1,[]],[-3],[-2],[-4]]
- Output
- [null,-3,-2,-2]
With k = 1 the class tracks the maximum, moving from -3 to -2 and staying at -2.
Example 3
- Input
- ["KthLargest","add","add","add"]
[[3,[-2,-2]],[-3],[-2],[0]]
- Output
- [null,-3,-2,-2]
The constructor has only k minus one entries, so no kth value is requested yet. Adding -3 makes [-2,-2,-3], whose third entry is -3. Adding another -2 makes the top three [-2,-2,-2]; adding 0 leaves [0,-2,-2]. Repeated negative values occupy separate ranks.