← Back to challenges

Ascending Consecutive Numbers

PythonHardstringshigher_order_functions

Instructions

Write a function that returns True if a string consists of ascending or ascending AND consecutive numbers.

Examples

ascending("232425") ➞ True
# Consecutive numbers 23, 24, 25

ascending("2324256") ➞ False
# No matter how this string is divided, the numbers are not consecutive.

ascending("444445") ➞ True
# Consecutive numbers 444 and 445.

Notes

A number can consist of any number of digits, so long as the numbers are adjacent to each other, and the string has at least two of them.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.