Error
|
|
---|---|
@Ibrahim Nash | 6379 |
@blackshadows | 6329 |
@mb1973 | 5358 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3357 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@ritiksethi21 | 1050 |
@aroranayan999 | 807 |
@RizulBansal | 685 |
@ashishtrehan002 | 538 |
@hemantgarg923 | 528 |
@simrangoyal | 526 |
@ronaldo77 | 520 |
@thanosagain | 505 |
@anishrajan | 505 |
@ssparteek470 | 495 |
@rahul2312 | 491 |
Complete Leaderboard |
A number is called a stepping number if all adjacent digits have an absolute difference of 1, e.g. '321' is a Stepping Number while 421 is not. Given two integers n and m, find the count of all the stepping numbers in the range [n, m].
Examples:
Input1 : n = 0, m = 21
Output1 : 13
Stepping no's are 0 1 2 3 4 5 6 7 8
9 10 12 21
Input2 : n = 10, m = 15
Output2 : 2
Stepping no's are 10, 12
Your Task:
You don't need to read input or print anything. Your task is to complete the function steppingNumbers() which takes the integer N and integer M as input parameters and returns the number of stepping numbers in the range between n and m.
Expected Time Complexity: O(log(M))
Expected Auxiliary Space: O(SN) where SN is the number of stepping numbers in the range
Constraints:
0 ≤ N, M ≤ 106
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes