Company: ConcertAI Software Engineering_30march
Difficulty: medium
Consider two unknown integers x and y . At an earlier time, two markers were placed on a number line at positions |x| and |y| , and all points between these two positions (inclusive) were selected. Later, two new markers were placed at positions |x - y| and |x + y| , and again all points between these two positions (inclusive) were selected. This second selected segment completely contains the first one, including its endpoints. Here, |z| denotes the absolute value of z . You are given a set of n distinct integers a1, a2, ..., an which represent possible values for x and y . Your task is to count how many unordered pairs of distinct values {x, y} chosen from this set satisfy the condition that the interval formed by |x| and |y| lies entirely within the interval formed by |x - y| and |x + y| . It is possible that no such pair exists. Example 1: Input: 3 2 5 -3 Output: 2 Explaination: Pair {2, 5}: The interval formed by |2| and |5| is [2, 5], while the interval from |2-5| and |2+5| is [3