Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

How many integers x with 1 ≤ x ≤ 2024 have NO two equal adjacent digits in their decimal representation?

  1. A. 1561
  2. B. 674
  3. C. 1570
  4. D. 1565

Correct answer: A. 1561

Digit DP: scan digits from the most significant, keeping a 'tight' flag (have we matched N's prefix) and the previous digit. Counting by brute force agrees, but the digit DP is the scalable method and needs the started flag so leading zeros are not treated as digits.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic