Given a string consisting of digits and '?' wildcards, count the number of valid string combinations where no two adjacent characters are identical. Examples: '001' outputs 0, '01?' outputs 2 (010, 012), '?1?' outputs 4 (010, 012, 110, 112), and '?1??' outputs 8.
Asked in the Round 5 (Global Manager) stage. This is a LeetCode Medium dynamic programming and string counting problem.
Implement count_valid_combinations(s). Each ? can be replaced by 0, 1, or 2. Return the exact number of replacements whose adjacent characters are all different. The input is a nonempty string containing only 0, 1, 2, and ?.
0, 1, 2, or ?? can be replaced only by 0, 1, or 2def count_valid_combinations(s):