No adjacent digits
Given a non-negative integer n, count how many integers x with 0 <= x <= n have NO two adjacent digits equal in their usual base-10 representation (e.g. 11 and 122 are invalid; 121 and 5 are valid; single-digit numbers including 0 are valid). 0 <= n <= 10^9. Return the count.
Implement
count_no_adjacent_equal(n: int) → intExamples
in
[22]out21What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[22]21not run yetsample