FunctionRacerProblemsRace

Rising Digits

BeginnerRecursionPython, JavaScript, TypeScript, Java, C++

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

n 1359
returns true

1 < 3 < 5 < 9, so every digit beats the one before it.

Example 2

n 1335
returns false

The two 3s are equal, and equal is not larger.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems