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
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution