Given two integers KX, and an array arr[] consisting of **N **distinct elements, the task is to find X elements closest to the Kth smallest element from the given array.

Examples:

Input:_ arr[] = {1, 2, 3, 4, 10}, K = 3, X = 2_

Output:_ 2 3_

_Explanation: _Kth smallest element present in the given array is 3 and X(= 2) closest array elements to 3 are {2, 3} or {3, 4}.

Therefore, the required output is 2 3.

Input:_ arr[] = {1, 9, 8, 2, 7, 3, 6, 4, 5, 10, 13, 12, 16, 14, 11, 15}, K = 3, X = 5_

Output:_ 1 2 3 4 5_

**Naive Approach: **The simplest approach to solve this problem is to sort the array and print X closest elements to the Kth smallest element of the given array using the two-pointers technique.

Time Complexity:_ O(N * log N)_

Auxiliary Space:_ O(1)_

#arrays #divide and conquer #hash #mathematical #searching #sorting #cpp-map #frequency-counting #java-hashmap #median-finding

Print X array elements closest to the Kth smallest element in the array
1.25 GEEK