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?
- A. 1561
- B. 674
- C. 1570
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many integers x with 1 ≤ x ≤ 500 have a decimal digit sum divisible by 3?
- You may swap the digits at exactly one pair of positions in the number 98368 (at most once). What is the largest number you can obtain?
- Children need greed factors [1, 2, 3, 5, 7]. Each child can receive at most one cookie, and a child is satisfied if the cookie size is at…
- In one move you may increase ALL but one element of the array [1, 2, 4, 7] by 1. What is the minimum number of moves to make all elements…
- Each move changes an element of [1, 2, 9, 10, 4, 4, 3] by exactly 1 (up or down). What is the minimum number of moves needed to make all…
- Ropes of lengths [4, 3, 2, 6] are joined two at a time, and joining costs the sum of their lengths. You may choose the order of joins…