Back to problems

Top K Closest Pairs in a Sorted Array

Algorithm · Apple · Hard

K Smallest Distance Pairs Medium You are given an integer array arr that is sorted in non‑decreasing order and an integer k. A pair is formed by choosing two distinct indices i and j with i < j. The distance of the pair is arr[i] - arr[j] . Find the k pairs with the smallest distances and return them as a list of value pairs [arr[i], arr[j]]. The list must be ordered by distance in ascending order. If two pairs have identical distance, they are ordered by the smaller index i…

Checking your access…