114. Kth Smallest Element
Core1000 ms256 MBSolved by 0%
Print the kth smallest value in the array, counting from 1.
Duplicates count separately, in [3, 1, 1] the 2nd smallest is 1.
Constraints - `1 ≤ k ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000`
Input
The first line contains two integers n and k.
The second line contains n space-separated integers.
Output
Print one integer, the kth smallest value, counting from 1, with duplicates counted separately.
Input5 2
7 10 4 3 20
Output4
Notefinds the second smallest in an unsorted array
Input3 2
3 1 1
Output1
Notehas duplicates, which count separately
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.