You get an integer array nums and an integer k. Imagine nums sorted from largest to smallest: return the value that lands in position k, counting from 1.
Repeated values each take their own position. In [8,8,3] the largest value is 8, the 2nd largest is also 8, and the 3rd largest is 3.
From largest to smallest the values are 9, 8, 7, 4, 1, and the second of those is 8.
The three 6s fill the first three positions, so the 3rd largest is still 6.
When k equals the array's length, the answer is the smallest value.
Constraints
1 <= k <= nums.length <= 10⁵-10⁴ <= nums[i] <= 10⁴You don't need the whole array in order: only the k largest values matter. Keep just those as you read the array.
8