Problem Β· Array

Get Discount Pairs 🍊

Learn this problem
● EasyAmazonFULLTIMEOA
See Amazon hiring insights

Problem statement

Amazon is offering a discount on every purchase of a pair of products whose price sum is divisible by x. Given the prices of n products, count the number of unordered index pairs (i, j) such that 0 <= i < j < n and (prices[i] + prices[j]) is divisible by x.

Return the number of such pairs.

Function

getDiscountPairs(x: int, prices: int[]) β†’ int

Examples

Example 1

x = 60prices = [31, 25, 85, 29, 35]return = 3
Example 1 illustration
The answer is 3 based on the pairs (31, 29), (25, 35), and (85, 35). Each pair sums to a number divisible by x.

Constraints

1 ≀ x ≀ 2 * 109

1 ≀ n ≀ 105

1 ≀ prices[i] ≀ 109

More Amazon problems

drafts saved locally
public int getDiscountPairs(int x, int[] prices) {
    // write your code here
}
x60
prices[31, 25, 85, 29, 35]
expected3
checking account