Company: Meesho
Difficulty: medium
Interesting Pairs A mathematics professor in a Senior Secondary High School decided to evaluate students for the Teachers Assessment based on their problem-solving skills. You are given an array of integers arr and an integer sumVal . The task is to pair up the elements of arr into interesting pairs . An unordered pair of distinct positions (i, j) is called interesting if |arr[i] - arr[j]| + |arr[i] + arr[j]| = sumVal that is, the sum of the absolute difference and the absolute sum of the values at those two positions equals sumVal . Find the number of interesting pairs in the array. Two pairs are the same pair if they use the same two positions, so (i, j) and (j, i) are counted only once. Example arr = [1, 4, -1, 2] sumVal = 4 There are two interesting pairs, (1, 4) and (3, 4) , because |arr[1] - arr[4]| + |arr[1] + arr[4]| = |1 - 2| + |1 + 2| = 1 + 3 = 4 |arr[3] - arr[4]| + |arr[3] + arr[4]| = |-1 - 2| + |-1 + 2| = 3 + 1 = 4 No other pair of positions gives 4 , so the answer is 2 . F