[LeetCode] Most Expensive Item That Can Not Be Bought

2979. Most Expensive Item That Can Not Be Bought

You are given two distinct prime numbers primeOne and primeTwo.

Alice and Bob are visiting a market. The market has an infinite number of items, for any positive integer x there exists an item whose price is x. Alice wants to buy some items from the market to gift to Bob. She has an infinite number of coins in the denomination primeOne and primeTwo. She wants to know the most expensive item she can not buy to gift to Bob.

Return the price of the most expensive item which Alice can not gift to Bob.

1
2
3
4
5
6
class Solution {
public:
int mostExpensiveItem(int primeOne, int primeTwo) {
return primeOne * primeTwo - primeOne - primeTwo;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2024/01/27/PS/LeetCode/most-expensive-item-that-can-not-be-bought/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.