16

Jumping Numbers

Difficulty: EASY
Avg. time to solve
15 min
Success Rate
85%

Problem Statement
Suggest Edit

You are given a positive integer N, your task is to 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 have an absolute difference of 1.For example 2, 23 and 4343456 are Jumping numbers but 296 and 89498 are not.

Note:
1. The difference between ‘9’ and ‘0’ is not considered as 1.
2. All single digit numbers are considered as Jumping Numbers. 
Input Format:
The first line contains an integer 'T' denoting the number of test cases.

The only line of each test case contains an integer N.  
Output Format:
For each test case, print all the Jumping Numbers smaller than or equal to N in ascending order. 
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function. 
Constraints:
1 <= T <= 100
1 <= N <= 10^8
Time Limit: 1 sec
Sample Input 1:
1
20
Sample Output 1:
0 1 2 3 4 5 6 7 8 9 10 12
Explanation of Sample Input 1:
These are all the jumping numbers from 0 to 12 as all the single digit numbers are jumping numbers and out of the two digit numbers only 10 and 12 are the jumping numbers less than 20 as the absolute difference in the adjacent digits of 10 and 12 is 1.
Sample Input 2:
2
1
30
Sample Output 2:
0 1
0 1 2 3 4 5 6 7 8 9 10 12 21 23 
Explanation of Sample Input 2:
These are all the jumping numbers from 0 to 1.
These are all the jumping numbers from 0 to 30, as all the single digit numbers are jumping numbers and out of the two digit numbers only 10,12,21,23 are jumping numbers. 23 is a jumping number because the absolute difference of 2 and 3 is 1, 21 is a jumping number because the absolute difference of 2 and 1 is 1.
Want to solve this problem? Login now to get access to solve the problems