FastPrepProject Estimates

Project Estimates

AT&T logoAT&T● EasyNEW GRADOA
Learn

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) → int

Examples

Example 1

projectCosts = [1,3,5]target = 2return = 2

The valid pairs are [1,3] and [3,5].

Example 2

projectCosts = [1,5,3,4,2]target = 2return = 3

The valid pairs are [1,3], [3,5], and [2,4].

Constraints

  • 2 <= projectCosts.length <= 200000.
  • 1 <= projectCosts[i] <= 2 * 10^9.
  • All values in projectCosts are distinct.
  • 1 <= target <= 10^9.

More AT&T problems

See AT&T hiring insights
public int countPairs(int[] projectCosts, int target) {
  // write your code here
}
projectCosts[1,3,5]
target2
expected2
Checking account…