Problem · Array
Get Max Discount Pairs
Learn this problemProblem statement
It is the third anniversary of Amazon Prime Day, and they have come up with amazing offers yet again! Customers who purchase a pair of products whose prices sum to a power of three receive a 50% discount. Given the prices of n products, find the number of pairs (i, j) such that i < j and (price[i] + price[j]) is a power of three.
Function
getMaxDiscountPairs(price: int[]) → int
Complete the function getMaxDiscountPairs in the editor below.
getMaxDiscountPairs has the following parameters:
int price[n]: the product prices
Returns
int: the number of pairs whose sum is a power of three.
Examples
Example 1
price = [2, 1, 8]return = 2
The following pairs will qualify for the discount (0, 1) since 2 + 1 = 3 and (1, 2) since 1 + 8 = 9 = 3^2. Return 2.
Constraints
🍎🍎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