FastPrepTop K Closest Pairs in a Sorted Array
Problems/Top K Closest Pairs in a Sorted Array

Top K Closest Pairs in a Sorted Array

Apple logoApple● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple full-time onsite interview. The report asks you to return the K pairs of values in a sorted array with the smallest absolute differences. It does not give a complete, portable set of rules. So here we chose a fixed way to do it: consider every index pair i

Given a nondecreasing integer array nums and an integer k, return the selected value pairs in priority order. Duplicate values and duplicate value pairs are retained when they come from different index pairs.

Function

topKClosestPairs(nums: int[], k: int) → int[][]

Examples

Example 1

nums = [1,2,4]k = 2return = [[1,2],[2,4]]

The differences are 1, 2, and 3.

Example 2

nums = [1,1,2]k = 3return = [[1,1],[1,2],[1,2]]

Index-distinct duplicate pairs are retained.

Constraints

  • 1 <= nums.length <= 500
  • 0 <= k <= 10000
  • nums is sorted in nondecreasing order.

More Apple Onsite Interview questions

  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • FIFO Mutex Operation TraceONSITE INTERVIEW · Seen Oct 2026
  • Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Parse Nested HTML into a TreeONSITE INTERVIEW · Seen Oct 2026
  • Thread-Safe Concurrent Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Palindrome Match PercentageONSITE INTERVIEW · Seen Sep 2026
  • Binary Tree Nodes at Distance KONSITE INTERVIEW · Seen Aug 2026
  • BST to Sorted Circular Doubly Linked ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Top Ten Largest FilesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
  • Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
  • Minimum Meeting Rooms Without a Sweep LineGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Top K Frequent ElementsCapgemini · ONSITE INTERVIEWCapgemini interview questions

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public int[][] topKClosestPairs(int[] nums, int k) {
      // Write your code here.
    }

}
Checking account…