FastPrepMinimum Absolute Difference
Problems/Minimum Absolute Difference

Minimum Absolute Difference

Microsoft logoMicrosoft● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The round is not named. The review lists this question for a Microsoft software engineering internship whose coding happened in two easy online interviews held after an HR interview. It gives the question as a one-line closest-pair task with no rules or limits.

Here the list has 2 to 10^4 integers in the signed 32-bit range, repeats are allowed (they give 0), and you return the smallest absolute difference as a 64-bit integer. Only the value is returned. The related Microsoft problem All Minimum-Difference Pairs asks for the pairs instead.

Our version is about 90% the same as the reported question.

You are given a list of integers nums. Over all pairs of different positions i and j, find the smallest value of |nums[i] - nums[j]| and return it.

The list may contain repeated values; two equal values at different positions give a difference of 0. The answer can be larger than a signed 32-bit integer can hold, so return it as a 64-bit integer.

Function

minimumDifference(nums: int[]) → long

Examples

Example 1

nums = [8,1,15,4]return = 3

In increasing order the numbers are 1, 4, 8, 15, and the gaps between neighbours are 3, 4 and 7. The closest two numbers are 1 and 4, so the answer is 3.

Example 2

nums = [5,9,5]return = 0

The value 5 appears twice, and two equal numbers differ by 0, so the answer is 0.

Example 3

nums = [-2147483648,2147483647]return = 4294967295

The only pair differs by 2147483647 - (-2147483648) = 4,294,967,295. That is more than a signed 32-bit integer can hold, so compute it with 64-bit integers.

Constraints

  • 2 <= nums.length <= 10^4
  • -2^31 <= nums[i] <= 2^31 - 1

More Microsoft Onsite Interview questions

  • 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
  • Totals from a Tiered Rate TableONSITE 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 interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long minimumDifference(int[] nums) {
        // Write your code here.
    }
}
Checking account…