You are given a sorted integer array arr[], an integer k, and an integer x. Your task is to find the k closest elements to x in the array. An element a is closer to x than element b if the absolute difference |a - x| is smaller than |b - x|. If there is a tie, choose the smaller element. Return the k closest elements in ascending order.
Topics
Companies
Articles
Examples:
N/A
Constraints:
1 = arr.length = 105
1 = k = arr.length
-104 = arr[i], x = 104
arr is sorted in ascending order
Companies:
Microsoft
Topics:
Binary Search
Please log in to access the Submissions tab, where you can review your progress and explore code submissions from other participants.
Please log in to access the Solution tab and view detailed answers and explanations.
Please log in to access the Discussion tab and join conversations with other participants.
Access Restricted: Please Login to access the code editor and test cases.