Bytelandian Gold Coins
MediumP3Coding
A gold coin has an integer value n. A bank can exchange a coin n for three coins worth floor(n/2), floor(n/3) and floor(n/4). Any coin can also be sold for its value in rupees (1:1). You cannot buy coins.
Starting with one coin of value n, return the maximum number of rupees you can end up with. You may exchange coins repeatedly.
Example 1
- Input
- n = 12
- Output
- 13
- Why
- Exchange 12 for 6 + 4 + 3 = 13, which beats selling it for 12.
Example 2
- Input
- n = 2
- Output
- 2
- Why
- 2 gives 1 + 0 + 0 = 1 if exchanged, so sell it for 2.
Example 3
- Input
- n = 0
- Output
- 0
Constraints
- 0 <= n <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 12. ⌘Enter runs, ⌘⇧Enter submits.