dsa · easy
Kth Smallest Element
GreyOrangeArrayHeapSortingFoundation
Return the k-th smallest element of unsorted nums (1-indexed).
Arguments
nums— the input array of integersk— 1-indexed rank of the smallest value to return (k = 1is the minimum)
**Example:** nums = [7,10,4,3,20,15], k = 3 → 7.
Constraints
1 <= k <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [7,10,4,3,20,15] 3 Expected: 7
Example 2
Input: [1] 1 Expected: 1