Kth Smallest Element
Mediumjavapythonccppjavascript
Given an unsorted array and an integer K, find the K-th smallest element (1-indexed).
Input Format
The first line contains two integers N and K. The second line contains N space-separated integers.
Output Format
Print the K-th smallest element.
Example 1
Input
6 3 7 10 4 3 20 15
Output
7
Explanation: Sorted: 3 4 7 10 15 20; the 3rd smallest is 7.
- 1 <= K <= N <= 100000
- -1000000000 <= A[i] <= 1000000000