Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@SherlockHolmes3 | 447 |

@codeantik | 441 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

@neverevergiveup | 381 |

@amrutakashikar2 | 355 |

@mahlawatep | 353 |

@murarry3625 | 352 |

Complete Leaderboard |

Given an array **arr[]** and a number **K** where K is smaller than size of array, the task is to find the **K ^{th} smallest** element in the given array. It is given that all array elements are distinct.

**Expected Time Complexity: **O(n)

**Input:**

The first line of input contains an integer **T,** denoting the number of testcases. Then T test cases follow. Each test case consists of three lines. First line of each testcase contains an integer **N** denoting size of the array. Second line contains N space separated integer denoting elements of the array. Third line of the test case contains an integer K.

**Output:**

For each testcase, in a newline, print the kth smallest element.

**Yout Task:**

Complete **kthSmallest **and return the k^{th} smallest element.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{5}

1 <= arr[i] <= 10^{5}

1 <= K <= N

**Example:
Input:**

2

6

7 10 4 3 20 15

3

5

7 10 4 20 15

4

**Output:**

7

15

**Explanation:
Testcase 1:** 3rd smallest element in the given array is 7.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Kth smallest element

...