Array ( [0] => [1] => questions [2] => Arrays [3] => Jump-numbers ) Arrays | Jump numbers | THE INQUISITIVE





Jump numbers

LEVEL:Beginner

Description

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).

Input Format

First line contains the size of the first array. Next line contains the m integers separated by the spaces.

Output Format

Print all jumping numbers


Example 1:

Input
20
Output
1 2 3 4 5 6 7 8 9  10 12
Example 2:

Input
30
Output
1 2 3 4 5 6 7 8 9 10 12 21 23
Example 3:

Input
40
Output
1 2 3 4 5 6 7 8 9 10 12 21 23 32 34

oops

Login to see Discussion




Approach

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.

oops

Login to see Solution