FastPrepFind K Closest Elements in a Sorted Array
Problems/Find K Closest Elements in a Sorted Array

Find K Closest Elements in a Sorted Array

Navi logoNavi● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Navi phone screen for a full-time role. The report points to a well-known problem. We chose the function signature, a fixed output order, and the input limits.

Our version is about 98% the same as the reported question.

Given a sorted integer array arr, an integer k, and a target x, return the k closest values to x in ascending order.

A value a is closer than b when |a - x| < |b - x|. For equal distances, the smaller value is closer.

Function

findClosestElements(arr: int[], k: int, x: int) → List<Integer>

Examples

Example 1

arr = [1,2,3,4,5]k = 4x = 3return = [1,2,3,4]

The four smallest distances belong to 1, 2, 3, and 4.

Example 2

arr = [1,2,3,4,5]k = 4x = -1return = [1,2,3,4]

The target lies left of the array, so the first four values are closest.

Constraints

  • arr is non-empty and sorted in nondecreasing order.
  • 1 <= k <= arr.length.
  • All values and x are signed integers.

Source note: Author-written prompt excerpt retained for source fidelity.

More Navi Phone Screen questions

  • Jump Game IIPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • K Closest Elements in a Sorted ArrayAmazon · PHONE SCREEN
  • Count Winning Dice Face PairsGoogle · PHONE SCREEN
  • Count Centaur Friend RequestsMeta · PHONE SCREEN
  • Count Triples That Can Form a TriangleAdobe · PHONE SCREEN
  • Find the Duplicate in a Read-Only ArrayNutanix · PHONE SCREEN
  • Target Sum Across Two Sorted ArraysSquarepoint Capital · PHONE SCREEN
  • Target Sum Across Two Sorted ArraysBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEW
  • 3Sum SmallerSalesforce · ONSITE INTERVIEW
  • K Smallest Squares from a Sorted ArrayUber · ONSITE INTERVIEW
See Navi hiring insights
Saved
class Solution {
    public List<Integer> findClosestElements(int[] arr, int k, int x) {
        // write your code here
    }
}
Checking account…