FastPrepAll Minimum-Difference Pairs
Problems/All Minimum-Difference Pairs

All Minimum-Difference Pairs

Microsoft logoMicrosoft● EasyNEW GRADINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source explicitly asks for all minimum-difference pairs and supplies the negative-number example. This exercise supplies distinct-value inputs, output ordering, the small-input rule and numeric bounds; it matches the reported task at about 90%.

Given an array of integers nums, find the minimum absolute difference between any two distinct input elements. Return every pair of values that attains that minimum.

For this exercise, all input values are distinct. Each output pair must be written as [smaller, larger], and the pairs must be sorted by their first value in ascending order. Return an empty array when there are fewer than two values.

Include every minimizing pair, even when several disjoint pairs or several adjacent pairs share the same minimum difference.

Function

minimumDifferencePairs(nums: int[]) → int[][]

Examples

Example 1

nums = [-1,-2,-4,-5,7,10]return = [[-5,-4],[-2,-1]]

The minimum absolute difference is 1. Both [-5,-4] and [-2,-1] attain it, in ascending output order.

Example 2

nums = [3,1,7,5]return = [[1,3],[3,5],[5,7]]

After ordering the values, every neighboring gap is 2, so all three pairs must be returned.

Example 3

nums = []return = []

Fewer than two values form no pair, so the result is empty.

Constraints

  • 0 <= nums.length <= 2000.
  • All values in nums are distinct.
  • -10^9 <= nums[i] <= 10^9.
  • Return each value pair once, in the stated order.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Sort Products by Aisle With Frozen Items LastInstacart · ONSITE INTERVIEWInstacart interview questions
  • Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Compress Consecutive Integer RangesDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Rank Transform an ArrayAgoda · ONSITE INTERVIEWAgoda interview questions
  • Sort Documents Left to RightFigma · ONSITE INTERVIEWFigma interview questions
  • Filter and Sort Scheduled TasksRippling · ONSITE INTERVIEWRippling interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)
  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[][] minimumDifferencePairs(int[] nums) {
        // Return all minimizing value pairs.
    }
}
Checking account…