Array ( [0] => [1] => questions [2] => Arrays [3] => Jump-numbers )
Given an integer X. You have to find all the jumping numbers less than X (Jumping number is a number that should have a difference 1 in adjacent digits of a number).
First line contains the size of the first array. Next line contains the m integers separated by the spaces.
Print all jumping numbers
20
1 2 3 4 5 6 7 8 9 10 12
30
1 2 3 4 5 6 7 8 9 10 12 21 23
40
1 2 3 4 5 6 7 8 9 10 12 21 23 32 34
Login to see Discussion
Approach1: Brute Force
Step-i) Implement a function called isJumping.
Step-ii) Check whether the difference between adjacent digits is equal to one or not.
Step-iii) Iterate a loop from 1 to a.
Step-iv) Check for every i is jumping or not.
Step-v) If it’s jumping add into the list, else leave.
Time Complexity: O(n)
Space Complexity: O(n)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution