FastPrepFastPrep
Problem Brief

Replace '?' to Avoid Adjacent Duplicates

OA

You are given a string s consisting of lowercase English letters ('a' to 'z') and the character '?'.

Each '?' can be replaced with any lowercase English letter.

Return the total number of ways to replace all '?' such that the final string has no two adjacent identical characters.

Since the answer may be large, return it modulo 10^9 + 7.

1Example 1

Input
s = "??"
Output
650
Explanation
  • First character: 26 choices
  • Second character: 25 choices (cannot equal the previous character)
  • Total ways = 26 * 25 = 650

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= s.length <= 10^5
  • s[i] is a lowercase English letter or '?'
public int replaceQuestionMarkToAvoidAdjacentDuplicates(String s) {
  // write your code here
}
Input

s

"??"

Output

650

Sign in to submit your solution.