All problems
Decode Ways II
Problem
Count the ways to decode a string of digits and star wildcards, where a star matches any digit 1 to 9 and letters map from 1 to 26.
Use dynamic programming with helper counts: a wildcard single digit gives 9 choices, and a leading wildcard contributes 15 valid two-digit groups. Return 0 for the empty string.
Hint
Count single-digit and two-digit transitions separately, using the previous two dp values.
Test cases
case 1
in: ["*"]
expected: 9
case 2
in: ["1*"]
expected: 18
case 3
in: ["2*"]
expected: 15
case 4
in: ["**"]
expected: 96
case 5
in: ["0"]
expected: 0
case 6
in: ["11106"]
expected: 2
Starter codePython
def num_decodings_ii(s):
# Your code here
pass6 test cases · run your code against them in the editor