Quick Overview

Find exactly k closest values to a target in an ascending integer array, returning them in sorted order. Binary-search the left edge of the answer window, apply the smaller-value tie break, and reach O(log(n-k+1)+k) time.

Find the K Closest Values in a Sorted Array

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Overview: Find exactly k closest values to a target in an ascending integer array, returning them in sorted order. Binary-search the left edge of the answer window, apply the smaller-value tie break, and reach O(log(n-k+1)+k) time.

Read the full LinkedIn Software Engineer interview experience this question came from

Loading…