117. Find K Closest Elements

Return the k elements of a sorted array that are closest to x.
Example 1
Input: arr = [1,1,2,3,4,5], k = 4, x = -1
Output: [1,1,2,3]
Explanation: The four elements closest to -1.
Example 2
Input: arr = [1,2,3,4,5], k = 4, x = 3
Output: [1,2,3,4]
Explanation: The four elements closest to 3.
arraysbinary searchmedium
JavaScript
Loading...
Line 1, Char 1