![]() |
VOOZH | about |
Write a program to check if a given integer is jumbled or not. A number is said to be Jumbled if for every digit, its neighbours digit differs by max 1.
Examples :
Input : 6765
Output : True
All neighbour digits differ by atmost 1.Input : 1223
Output : TrueInput : 1235
Output : False
Approach:
Below is the implementation of the above idea :
True False
Time complexity: O(log10N), where N is the given number.
Auxiliary space: O(1), as constant space is being used.
Related Article :
Stepping Numbers