Company: IBM
Difficulty: medium
2. 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. Example n = 3 projectCosts = [1, 3, 5] target = 2 There are 2 pairs [1, 3] and [3, 5] with the target difference target = 2 . Therefore, 2 is returned. Input Format The first line contains an integer n , the number of elements in the array. The second line contains n space-separated integers, representing the array projectCosts . The third line contains an integer target , the absolute difference. Output Format Return an integer representing the number of distinct pairs with an absolute difference of target . Constraints 5 ≤ n ≤ 10 5 0 < projectCosts[i] ≤ 2 × 10 9 Each projectCosts[i] is distinct, i.e., unique within the array. 1 ≤ target ≤ 10 9 Examples Input: 5 1 5 3 4 2 2 Output: 3 The following pairs meet the target difference of 2: (1, 3) (5, 3) (4, 2)