87. Find Kth Smallest and Kth Largest Element

You are given an array of n unsigned 8-bit integers (uint8_t) and a number k. Your task is to:

  • Find the k-th smallest and k-th largest values from the array
  • Output both values in a single line: smallest largest

Important Notes:

  • Assume: 1 ≤ k ≤ n
  • Do not use built-in sort functions
  • Use a simple sorting approach (bubble/selection) and pick elements by index
     

Example-1

Input: n = 5, arr = [10 3 5 2 7], k = 2
Output: 3 7


Example-2

Input: n = 4, arr = [8 1 9 6], k = 1
Output: 1 9


Example-3

Input: n = 3, arr = [10 20 30], k = 3
Output: 30 10


 

Loading...

Input

5 10 3 5 2 7 2

Expected Output

3 7