Company: Service Now
Difficulty: medium
Question 2 A number of bids are received for a project. Determine the number of distinct pairs of project costs where their absolute difference is some target value. Two pairs are distinct if they differ in at least one value. Function Description Complete the function countPairs in the editor below. countPairs has the following parameter(s): int projectCosts[n] : array of integers int target : the target difference Returns int : the number of distinct pairs in projectCosts with an absolute difference of target Constraints 5 ≤ n ≤ 10 5 0 9 Examples Example 1 Input: n = 3 projectCosts = [1, 3, 5] target = 2 Output: 2 There are 2 pairs [1,3], [3,5] with the target difference target = 2. Therefore, 2 is returned. Sample Case 0 Input: n = 5 projectCosts = [1, 5, 3, 4, 2] target = 2 Output: 3 Count the number of pairs in projectCosts whose difference is target = 2. The following three pairs meet the criterion: (1, 3), (5, 3), and (4, 2). Sample Case 2 Input: n = 6 projectCosts = [2, 4, 6, 8