#C5241. Find the Kth Smallest Element
Find the Kth Smallest Element
Find the Kth Smallest Element
Given an array of integers, your task is to determine the kth smallest element when the array is sorted in non-decreasing order.
The problem is defined as follows:
Given an array \(A = [a_1, a_2, \ldots, a_n]\) of \(n\) integers and an integer \(k\), find the element that would be in the \(k\)th position if the array were sorted in ascending order. In other words, find \(A_{(k)}\) where \(A_{(1)} \leq A_{(2)} \leq \cdots \leq A_{(n)}\).
This problem tests your understanding of sorting algorithms and order statistics.
inputFormat
The input is given through standard input (stdin) and consists of two lines. The first line contains two integers (n) and (k), where (n) is the number of elements in the array and (k) indicates the (k)th smallest element to find. The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
Output a single integer to standard output (stdout), which is the (k)th smallest element in the sorted array.## sample
6 2
3 2 1 5 6 4
2