FastPrepCount Stepping Numbers In Range

Count Stepping Numbers In Range

Amazon logoAmazon● HardFULLTIMEPHONE SCREEN

Problem statement

A stepping number is an integer whose adjacent digits differ by exactly 1. Every one-digit integer, including 0, is a stepping number.

Given two integers low and high, return the number of stepping numbers in the inclusive range [low, high].

Function

countSteppingNumbers(low: long, high: long) → int

Examples

Example 1

low = 0high = 21return = 13

The stepping numbers in [0, 21] are 0 through 9, plus 10, 12, and 21.

Example 2

low = 10high = 15return = 2

Only 10 and 12 are stepping numbers in [10, 15].

Constraints

  • 0 <= low <= high <= 10^15.

More Amazon problems

See Amazon hiring insights
Saved
public int countSteppingNumbers(long low, long high) {
  // Write your code here.
}
low0
high21
expected13
Checking account…