582. Most Expensive Item That Can Not Be Bought

In a special marketplace, items are priced at every positive integer value. That means for any x > 0, there exists an item that costs exactly x.

There are two types of coins, each with denominations coinA and coinB, where both values are distinct prime numbers. The task is to determine the highest price that cannot be formed using any combination of these two coin values.

Return the price of the most expensive item that cannot be purchased.

Example 1:

Input: coinA = 3, coinB = 7

Output: 11

Explanation: The item prices that cannot be bought using only coins of 3 and 7 are [1,2,4,5,8,11].

It can be shown that for all values greater than 11, Alice can use some combination of 3 and 7 to buy them.

Example 2:

Input: coinA = 2, coinB = 5

Output: 3

Explanation: The items that cannot be purchased are [1,3]. Any price higher than 3 can be formed using 2 and 5.

Now Your Turn!

Pick the correct output for the given input

Input: coinA = 5, coinB = 11

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 < coinA, coinB < 104
  • coinA and coinB are both prime numbers
  • coinA * coinB < 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int mostExpensiveItem(int primeOne, int primeTwo) {
 
}
};
Test Case

Input:

Coin A
Coin B