Tap here to switch tabs
Problem
Submissions

Problem: Decode Ways II

med
30 min
Try to solve the Decode Ways II problem.

Statement

A message containing uppercase English letters from 'A' to 'Z' can be encoded into digits using the following mapping:

  • 'A' →\rightarrow $1$

  • 'B' →\rightarrow $2$

  • …

  • 'Z' →\rightarrow $26$

To decode an encoded message, all digits must be grouped and mapped back into letters according to the reverse mapping. Multiple valid decodings may exist.

In addition to the digits from $0$ to $9$, an encoded string may also contain the wildcard character '*', which can represent any single digit from $1$ to $9$ inclusive.

Given a string s containing digits and '*' characters, return the total number of ways to decode it. Since the result can be very large, return it modulo 109+710^9 + 7.

Note: A valid grouping cannot contain leading zeros (for example, "06" cannot be mapped to 'F' because "6" alone is valid, but "06" is invalid).

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is a digit or '*'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Decode Ways II

med
30 min
Try to solve the Decode Ways II problem.

Statement

A message containing uppercase English letters from 'A' to 'Z' can be encoded into digits using the following mapping:

  • 'A' →\rightarrow $1$

  • 'B' →\rightarrow $2$

  • …

  • 'Z' →\rightarrow $26$

To decode an encoded message, all digits must be grouped and mapped back into letters according to the reverse mapping. Multiple valid decodings may exist.

In addition to the digits from $0$ to $9$, an encoded string may also contain the wildcard character '*', which can represent any single digit from $1$ to $9$ inclusive.

Given a string s containing digits and '*' characters, return the total number of ways to decode it. Since the result can be very large, return it modulo 109+710^9 + 7.

Note: A valid grouping cannot contain leading zeros (for example, "06" cannot be mapped to 'F' because "6" alone is valid, but "06" is invalid).

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is a digit or '*'