Rising Digits
Return True if the decimal digits of the non-negative integer n, read from left to right, are strictly increasing, so that every digit is larger than the digit before it, and False otherwise. A number with a single digit, including 0, counts as rising.
A loop over the digits works, but the recursive view is short: n is rising when it has one digit, or when its last digit is larger than the digit just before it and n // 10 is rising too.
For example, 1359 gives True, while 1335 (two equal digits) and 1532 give False.
Example 1
1 < 3 < 5 < 9, so every digit beats the one before it.
Example 2
The two 3s are equal, and equal is not larger.
Constraints
0 <= n <= 1000000000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Recursion problems
- Ruler PatternBeginner
- Same Both WaysBeginner
- Suffix ChainBeginner
- Wheels in the RowBeginner
- Deep ReverseEasy
- Depth-Weighted SumEasy
- Digit Product StepsEasy
- Downhill SpillEasy