Count Digit Replacements with No Equal Adjacent Digits
Problem statement
You are given a string s containing digits from 0 through 9 and question marks.
Replace every ? with one digit so that no two adjacent digits are equal. Return the number of valid replacements modulo 10^9 + 7.
Function
getNumOfWays(s: String) → intExamples
Example 1
s = "1?3?"return = 72The first question mark may be any digit except 1 and 3, giving 8 choices. The last may be any digit except 3, giving 9 choices. Therefore the result is 8 * 9 = 72.
Example 2
s = "??"return = 90The first position has 10 choices, and the second has 9 choices different from the first.
Constraints
1 <= s.length <= 10^5scontains only digits from0through9and?.