#C3829. Kth Smallest Element
Kth Smallest Element
Kth Smallest Element
You are given an unsorted array of integers and an integer k. Your task is to find the kth smallest element in the array. The kth smallest element is defined as the element which would appear in the kth position if the array was sorted in ascending order. Using the Quickselect algorithm, which has an expected time complexity of \(O(n)\), you should compute the result efficiently.
Note: The value of k is 1-indexed, meaning that k = 1 corresponds to the smallest element of the array.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains two space-separated integers \(N\) and \(k\), where \(N\) is the number of elements in the array and \(k\) is the kth position (1-indexed).
- The second line contains \(N\) space-separated integers representing the array elements.
outputFormat
Output a single integer to standard output (stdout): the kth smallest element in the provided array.
## sample6 2
7 10 4 3 20 15
4
</p>