Skip to the code
cf.
+50 XP

#564 Page Numbers Without Repeated Neighbors

hard

A printing service charges extra for page numbers where two neighboring digits are the same, like 112 or 3455, because the font kerning looks odd. A document uses page numbers from low to high.

Write countCleanPages(low, high) that returns how many integers from low to high (inclusive) have no two equal neighboring digits.

Example 1

Input: low = 95, high = 112
Output: 13

There are 18 numbers, minus 99, 100, 110, 111, and 112.

Example 2

Input: low = 5, high = 5
Output: 1

A single digit has no neighbors.

Constraints

  • 1 <= low <= high <= 10^15
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).