Company: Cohesity
Difficulty: medium
Buy One Get One Free Rohit is the owner of a company. He is planning to give a buy one get one offer on products. His team decided that a product b can be given free with another product a if the price of the costlier product a is more than twice of the price of product b. So, they want to find the number of unique pairs (a, b) among the total number of products N and they need your help to do the same. You are given the prices of the product in an array arr which contains integers. Find the number of unique pairs which satisfies the above condition. Input Format The input contains a list of integers denoting the price of products. Type: array.integer arr Output Format The output is a single integer which denotes the number of unique pairs which can be formed. Type: integer64 Example Input: arr: [2,4,3,5,1] Output: 3 Explanation: The pairs are: arr[1] = 4, arr[4] = 1, 4 > 2 * 1 arr[2] = 3, arr[4] = 1, 3 > 2 * 1 arr[3] = 5, arr[4] = 1, 5 > 2 * 1 Constraints 1 <= arr.length <= 5000