Jumping Digits
Medium
number-theory
digit-manipulation
bfs
generation
Problem Description
A "jumping number" is a positive integer where every pair of adjacent digits differs by exactly 1. Find all jumping numbers less than or equal to N. Single-digit numbers (0-9) are considered jumping numbers.
Input Format
A single integer N.
Output Format
All jumping numbers ≤ N in ascending order, space-separated on one line.
Constraints
• 0 ≤ N ≤ 100000
• Adjacent digits must differ by exactly 1
• Single digits (0-9) are jumping numbers
• Return numbers in ascending order
• Include 0 if N ≥ 0
Sample Input/Output
Input:
50
Output:
0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45
Explanation
Jumping numbers ≤ 50: All single digits (0-9), then 10 (|1-0|=1), 12 (|1-2|=1), 21 (|2-1|=1), 23 (|2-3|=1), 32 (|3-2|=1), 34 (|3-4|=1), 43 (|4-3|=1), 45 (|4-5|=1).
Solution Hints
85
Points
Points
2000ms
Time Limit
Time Limit
128MB
Memory Limit
Memory Limit
Code Editor
Register to Access Code Editor
Create a free account to solve coding problems and track your progress.
Register Now