Problems > Adjacent Digits Differ by One > Editorial

Adjacent Digits Differ by One — Solution & Editorial

Back to the Problem

Digit DP with prefix difference and tight/leading flags.

Complexity: O(digits · states)

Watch out: Leading zeros exempt; a single-digit number trivially satisfies the condition.