FastPrepCount Minimum-Difference Pairs
Problems/Count Minimum-Difference Pairs

Count Minimum-Difference Pairs

Shield AI logoShield AI● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Shield AI coding interview asks for the number of pairs with the smallest difference. We assume the input values are distinct, and we set a limit on the input size. Our version is about 85% the same as the reported question.

Given an array values of distinct integers, find the minimum absolute difference between any two values and return the number of unordered pairs that have that difference.

Function

countMinimumDifferencePairs(values: int[]) → int

Examples

Example 1

values = [4,2,1,3]return = 3

The minimum difference is 1, achieved by (1,2), (2,3), and (3,4).

Example 2

values = [1,5,9]return = 2

Constraints

  • 2 <= values.length <= 100000.
  • All values are distinct and fit in a signed 32-bit integer.

Similar questions at other companies

  • Majority ElementByteDance · PHONE SCREENByteDance interview questions
  • Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Assign CookiesAmazon · PHONE SCREEN
  • Sort by Checking PermutationsMercor · PHONE SCREENMercor interview questions
  • Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Parse and Sort Integer DataLegora · PHONE SCREEN

Shield AI interview experiences

  • Shield AI SWE Intern Interviews: 4 Experiences
See Shield AI hiring insights
Saved
class Solution {
    public int countMinimumDifferencePairs(int[] values) {
      // write your code here
    }
}
Checking account…