 1

# Kth Smallest Element

Difficulty: EASY
Avg. time to solve
15 min
Success Rate
85%

Problem Statement
Suggest Edit

#### Note: All the elements in the array are distinct.

##### Input format
``````The first line of input contains an integer 'T' representing the number of the test case. Then the test case follows.
The first line of each test case contains two space-separated integers ‘N’ representing the size of the array and ‘K’.
The second line contains N space-separated integers that represent elements of the array ARR.
``````
##### Output format
``````For each test case, return the Kth smallest element of the array
``````
##### Note:
``````You do not need to print anything; it has already been taken care of. Just implement the given function.
``````
##### Constraints:
``````1 <= T <= 100
1 <= N <=10^4
1 <= K <= N
1 <= ARR[i] <= 10^9

Time limit: 1 second
``````
##### Sample Input 1:
``````3
6 3
1 2 3 4 5 6
5 4
1 3 8 6 2
1 1
5
``````
##### Sample Output 1:
``````3
6
1
``````
##### Explanation of Input 1:
``````(i) Sorted array will be 1 2 3 4 5 6, this shows that 3 is the third-smallest element in the array.
(ii) Sorted array will be 1 2 3 6 8, this shows that 6 is the fourth-smallest element in the array.
(iii) Sorted array will be 5, this shows that 5 is the smallest (and only) element in the array.
``````
##### Sample Input 2:
``````3
2 2
1 14
2 1
1 14
3 2
6 7 9
``````
##### Sample Output 2:
``````14
1
7
``````
##### Explanation of Input 2:
``````(i) Sorted array will be 1 14, this shows that 14 is the second-smallest element in the array.
(ii) Sorted array will be 1 14, this shows that 1 is the smallest element in the array.
(iii) Sorted array will be 6 7 9, this shows that 7 is the second-smallest element in the array.
`````` Want to solve this problem? Login now to get access to solve the problems