Jumping Numbers Finder
Given a positive integer n, find all the 'Jumping Numbers' smaller than or equal to n. A number is defined as a 'Jumping Number' if all adjacent digits in it differ by 1. The output should be a sorted list of these numbers.
[ 10 ]
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
Explanation. All digits and 10 are jumping numbers less than or equal to 10.
[ 15 ]
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12 ]
Explanation. All single-digit numbers are jumping numbers. From 10 to 15, only 10 and 12 qualify as jumping numbers.
[ 30 ]
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 21, 23 ]
Explanation. Numbers like 10, 12, 21, and 23 show the jumping number property where consecutive digits differ by 1.
Follow-up: Can you optimize your solution to run in linear time?
The input number, `n`, will be greater than 0 and less than or equal to 100,000.
- Views
- 13