Jumping Numbers [ Google – Microsoft – Amazon ]

Problem:Given a positive number x, print all Jumping Numbers smaller than or equal to x. A number is called as a Jumping Number if all adjacent digits in it differ by 1. The difference between ‘9’ and ‘0’ is not considered as 1. All single digit numbers are considered as Jumping Numbers. For example 7, 8987 and 4343456 are Jumping numbers but 796 and 89098 are not.

Link

Solution Hint: use BFS to find the next digit, constraint: new digit +/- 1 from the previous digit.

 

Comments are closed.