FastPrepFastPrep
Problem Brief

Get Max Discount Pairs

FULLTIMEOA
See Amazon online assessment and hiring insights

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 Description

Complete the function getMaxDiscountPairs in the editor below.

getMaxDiscountPairs has the following parameters:

  1. int price[n]: the product prices

Returns

int: the number of pairs whose sum is a power of three.

1Example 1

Input
price = [2, 1, 8]
Output
2
Explanation

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

Limits and guarantees your solution can rely on.

๐ŸŽ๐ŸŽ
public int getMaxDiscountPairs(int[] price) {
  // write your code here
}
Input

price

[2, 1, 8]

Output

2

Sign in to submit your solution.