Count Minimum-Difference Pairs
Updated
Problem statement
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[]) → intExamples
Example 1
values = [4,2,1,3]return = 3The minimum difference is 1, achieved by (1,2), (2,3), and (3,4).
Example 2
values = [1,5,9]return = 2Constraints
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