Search
⌘K

Leetcode 658. Find K Closest Elements

Given a sorted array, return the k integers closest to x (ties broken by smaller value) in ascending order. Use the sorted property to locate the optimal contiguous window of size k (e.g., via binary search on the window start or two-pointer shrinking).

Asked at:

Microsoft

Microsoft

Meta


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Early April, 2026

Microsoft

Microsoft

Senior

Given an array representing n positions along a straight line. Find k (where k <= n) elements from the array such that the minimum distance between any two (consecutive points among the k points) is maximized. arr[] = {1, 2, 8, 4, 9}, k = 3

Mid July, 2025

Meta

Manager

Your account is free and you can post anonymously if you choose.