


Given an array/list ‘ARR' = [ 3, 2, 4, 5, 6 ] and 'K' = 3. The 3rd smallest element is "4" because the order of numbers is [ 2, 3, 4, 5, 6 ].
The first line of input contains an integer ‘T’ denoting the number of test cases. The next ‘T’ lines represent the ‘T’ test cases.
The first line of input contains two space-separated integers ‘N’ and ‘K’.
The second line of input contains the ‘N’ space-separated integer which denotes the element of array ‘ARR’.
For every test case, print the ‘K-th’ smallest element in the array 'ARR'.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= K <= N <= 5000
-10^9 <= ARR[i] <= 10^9
Where ‘T’ represents the number of test cases, ‘N’ is the number of elements in array ‘ARR’ , ‘K’ denotes an integer. ‘ARR[i]’ represents the value of the number at ‘i’ position in ‘ARR’.
Time Limit: 1 sec
The algorithm will be-
Approach: The basic idea is that, create a min-heap and insert all the elements in the min-heap one by one. In the end, pop K elements one by one, so the ‘K-th’ element will be the answer as every time the smallest element will be popped out from the minHeap.
The properties of max-heap are -