Description
Solutions
Find Number of Interesting Pairs
📚RELATED PROBLEMS
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
, and 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]|
, 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.
Example 1:
Input: arr = [1, 4, -1, 2], sumVal = 4
Output: 2
Explanation: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.
Constraints:
TO-DO

Related Problems
Testcase
Result
Case 1
input:
output: