PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates array manipulation, sorting-based reasoning, and the ability to generate ordered value pairs that reflect minimum absolute differences while handling ordering and duplicates.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Machine Learning Engineer

Find pairs with the minimum absolute difference

Company: Microsoft

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an integer array (not necessarily sorted), find the minimum absolute difference between any two distinct elements. Return all pairs of values that achieve this minimum difference. Requirements: - Each pair should be ordered as [smaller, larger]. - Return pairs in ascending order by their first element (and then second if needed). Example: Input: [-1, -2, -4, -5, 7, 10] Output: [[-5, -4], [-2, -1]] Explanation: The minimum difference is 1, achieved by (-5, -4) and (-2, -1).

Quick Answer: This question evaluates array manipulation, sorting-based reasoning, and the ability to generate ordered value pairs that reflect minimum absolute differences while handling ordering and duplicates.

Return all value pairs achieving the minimum absolute difference, ordered ascending.

Constraints

  • Pairs are returned as [smaller, larger]

Examples

Input: ([-1, -2, -4, -5, 7, 10],)

Expected Output: [[-5, -4], [-2, -1]]

Explanation: Example pairs.

Input: ([4, 2, 1, 3],)

Expected Output: [[1, 2], [2, 3], [3, 4]]

Explanation: Several adjacent differences tie.

Input: ([1, 1, 1],)

Expected Output: [[1, 1]]

Explanation: Duplicate values give difference zero.

Input: ([5],)

Expected Output: []

Explanation: Need two values.

Hints

  1. Sort; the minimum difference must occur between adjacent sorted values.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)