Find K Closest Elements

Medium · Binary Search · about 20 minutes

Asked at Meta, Amazon, Google, LinkedIn, Uber.

Given a sorted integer array arr and integers k and x, return the k elements closest to x, sorted ascending. a is closer than b if |a - x| < |b - x|, or if the distances are equal and a < b.

Related guides