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
Meta
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Early April, 2026
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
Hello Interview Premium
Your account is free and you can post anonymously if you choose.