When started=false: placing 0 keeps started=false. Placing 1-9 sets started=true and lastDigit. When started=true: only place digits within 1 of lastDigit. Update lastDigit for next position. Edge case: what's the first digit of 0? We define single-digit numbers as valid (no adjacent pair to check). Time: O(n⋅2⋅10⋅2)=O(n) where n=log10N. The constants are small. Space: O(logN⋅10) for memoization table.
Time complexity: O(logN⋅10).
Space complexity: O(logN).