You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the Kth smallest element in the given array. It is given that all array elements are distinct.
4
+
5
+
// Example 1:-
6
+
7
+
// Input:
8
+
// N = 6
9
+
// arr[] = 7 10 4 3 20 15
10
+
// K = 3
11
+
12
+
// Output : 7
13
+
14
+
// Explanation :
15
+
// 3rd smallest element in the given
16
+
// array is 7.
17
+
18
+
// Example 2:
19
+
20
+
// Input:
21
+
// N = 5
22
+
// arr[] = 7 10 4 20 15
23
+
// K = 4
24
+
25
+
// Output : 15
26
+
27
+
// Explanation :
28
+
// 4th smallest element in the given
29
+
// array is 15.
30
+
31
+
// Your Task:
32
+
// You don't have to read input or print anything. Your task is to complete the function kthSmallest() which takes the array arr[], integers l and r denoting the starting and ending index of the array and an integer K as input and returns the Kth smallest element.
0 commit comments