This is a verified interview question from De-shaw. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Interesting Pairs of Numbers" covers key patterns like Other.
"### Problem 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. ### Input - arr: an array of integers - sumVal: an integer ### Output - An integer value denoting the number of interesting pairs ### Example - arr = [1, 4, -1, 2] - sumVal = 4 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."
Join thousands of developers practicing for De-shaw.