Connection Status:
Competition Arena > JumpyNum
SRM 300 · 2006-04-27 · by dgoodman · Dynamic Programming
Class Name: JumpyNum
Return Type: int
Method Name: howMany
Arg Types: (int, int)
Problem Statement

Problem Statement

A jumpy number is a positive integer, all of whose adjacent digits differ by at least 2. For example,
        
        NOT JUMPY: 28459, 28549, 1091919, 97753, 111111
            JUMPY: 290464, 13131313, 97539753, 5
Create a class JumpyNum that contains a method howMany that is given low and high and returns the number of jumpy numbers that are between low and high, inclusive.

Constraints

  • low is between 1 and 2,000,000,000, inclusive.
  • high is between low and 2,000,000,000, inclusive.
Examples
0)
1
10
Returns: 9

All the single digit numbers are jumpy, but 10 isn't since 1 and 0 differ by only 1.

1)
9
23
Returns: 9

The jumpy ones are 9,13,14,15,16,17,18,19,20

2)
2000000000
2000000000
Returns: 0
3)
1
13
Returns: 10
4)
22
99
Returns: 56

Submissions are judged against all 68 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class JumpyNum with a public method int howMany(int low, int high) · 68 test cases · 2 s / 256 MB per case

Submitting as anonymous