Project Estimates
Problem statement
A project has received several bids. Given the distinct integer values in projectCosts and a positive integer target, determine how many distinct value pairs have an absolute difference equal to target.
Two pairs are distinct when they differ in at least one value.
Function
countPairs(projectCosts: int[], target: int) → intExamples
Example 1
projectCosts = [1,3,5]target = 2return = 2The valid pairs are [1,3] and [3,5].
Example 2
projectCosts = [1,5,3,4,2]target = 2return = 3The valid pairs are [1,3], [3,5], and [2,4].
Constraints
2 <= projectCosts.length <= 200000.1 <= projectCosts[i] <= 2 * 10^9.- All values in
projectCostsare distinct. 1 <= target <= 10^9.