Problem Β· Array
Get Discount Pairs π
Learn this problemProblem 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[]) β intExamples
Example 1
x = 60prices = [31, 25, 85, 29, 35]return = 3
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
- Secure Maximum DeliveriesOA Β· Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW Β· Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN Β· Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN Β· Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW Β· Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW Β· Seen Jul 2026
- Maximum System Memory CapacityOA Β· Seen Jul 2026
- Package Delivery SystemOA Β· Seen Jul 2026