values sorted in non-decreasing order, a number k and a number target. Pick the k elements closest to target and return them in ascending order.
Element a is closer than element b if |a - target| < |b - target|; when the distances are equal, the smaller value counts as closer. Repeated values are separate elements, so several of them may be picked.values=[2, 4, 6, 8, 10], k=3, target=7 → [4, 6, 8]
6 and 8 are 1 away, then 4 and 10 are both 3 away, and the smaller one, 4, wins.
values=[1, 1, 3, 20], k=2, target=30 → [3, 20]
20 is the closest, followed by 3.
values=[-5, 0, 5], k=1, target=-1 → [0]
values is sorted in non-decreasing ordervalues=[2, 4, 6, 8, 10], k=3, target=7
[4, 6, 8]
Run checks the first 3 tests in your browser. Submit checks all 131 tests on the server, hidden ones included.