Find Kth Smallest and Largest Element
Description
- Given an array
arr[]and an integerKwhereKis smaller than size of array, the task is to find theKthsmallest and largest element in the given array. It is given that all array elements are distinct.
Examples
> Case 1:
Input: arr = [21, 43, 32, 30], K = 2
Output: [30, 32]
> Case2:
Input: arr = [10, 5, 8, 3, 2, 7, 1], K = 3
Output: [3, 7]Constraints
1 <= N <= 10^51 <= arr[i] <= 10^51 <= K <= N