Reach N by Multiplying by 10 or 20
EasyP3Coding
You start with exactly 1 rupee. You may apply two operations any number of times, in any order: multiply the amount by 10, or multiply it by 20. Return true if you can end with exactly n rupees, otherwise false.
Zero operations are allowed, so n = 1 is reachable.
Example 1
- Input
- n = 1
- Output
- true
- Why
- 10 = 1 * 10.
Example 2
- Input
- n = 10
- Output
- true
- Why
- 20 = 1 * 20.
Example 3
- Input
- n = 20
- Output
- true
- Why
- 200 = 1 * 10 * 20.
Constraints
- 1 <= n <= 10^15
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.