#K61192. K-th Smallest Element Finder
K-th Smallest Element Finder
K-th Smallest Element Finder
You are given (T) test cases. Each test case consists of an array and an integer (k). Your task is to find the (k)-th smallest element in the array using a min-heap based approach. The (k)-th smallest element is defined as the element that would appear in the (k)-th position when the array is sorted in non-decreasing order.
Formally, for an array (A) of size (n), find the element (A_{(k)}) such that there are exactly (k-1) elements in (A) that are less than or equal to (A_{(k)}).
Example: For the array [7, 10, 4, 3, 20, 15] with (n = 6) and (k = 3), the sorted order is [3, 4, 7, 10, 15, 20] and the 3rd smallest element is 7.
inputFormat
The first line of input contains an integer (T), representing the number of test cases. Each test case consists of two lines:
- The first line contains two integers (n) and (k) (with (1 \leq k \leq n)), where (n) is the size of the array and (k) is the order of the smallest element to find.
- The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
For each test case, output the (k)-th smallest element on a new line.## sample
2
6 3
7 10 4 3 20 15
5 2
1 2 999999999 1000000000 2
7
2
</p>