A mathematics professor in a Senior Secondary High School decided to evaluate students for the Teachers Assessment based on their problem-solving skills.
Given an array of integers arr, an integer, sumVal, the task is to pair the elements in arr into interesting pairs. Find the number of interesting pairs in the array. An unordered pair (i, j) is defined to be interesting if |arr_i - arr_j| + |arr_i + arr_j| = sumVal (i.e., the sum of absolute difference and absolute sum at the values in respective indices is equal to sumVal). The goal is to find the number of interesting pairs in the array.
Then, there are two interesting pairs, (1, 4) and (3, 4). Because, |arr_1 - arr_4| + |arr_1 + arr_4| = |1 - 2| + |1 + 2| = 4. |arr_2 - arr_4| + |arr_3 + arr_4| = |-1 - 2| + |-1 + 2| = 4.
Hard