dsa12 min read
Find K Closest Elements — Binary Search on Window Boundary [LC 658, Amazon, Meta]
Find the k closest elements to x in a sorted array in O(log(n-k) + k) by binary searching for the optimal left boundary of the result window rather than searching for x itself.
Read →