Decode Ways II
A hard-tier problem at 31% community acceptance, tagged with String, Dynamic Programming. Reported in interviews at PhonePe and 0 others.
Decode Ways II is a hard string DP problem that hits different when the input includes wildcards. You've likely seen the classic single-digit-or-two-digit decode problem, but this version throws '*' characters that can represent any digit from 1 to 9, or 0 to 9 depending on context. The acceptance rate sits around 31%, which tells you most candidates either miss the wildcard logic or blow the modular arithmetic. PhonePe has asked this. If you hit it live and blank on how to handle the combinatorial explosion of wildcard states, StealthCoder solves it invisible to the proctor.
Companies that ask "Decode Ways II"
Decode Ways II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trick is DP with careful state tracking: at each position, you count the number of valid decodings so far. With wildcards, a single '*' can spawn multiple decode paths, and you must account for that without blowing up the runtime. The naive recursion explodes because you're recomputing the same subproblems; memoization (or bottom-up DP) is non-negotiable. Common failure: forgetting that a '*' as the second character of a potential two-digit code can be 0 to 9, but only 1 to 9 work when preceded by '1', and only 0 to 6 work when preceded by '2'. Edge cases abound: leading zeros, consecutive wildcards, and modulo arithmetic errors. String and Dynamic Programming converge here. StealthCoder hedges the moment you realize the state transitions are more complex than you prepped for.
Pattern tags
You know the problem.
Make sure you actually pass it.
Decode Ways II recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Decode Ways II interview FAQ
How hard is this compared to the classic Decode Ways problem?+
Significantly harder. Classic Decode Ways is a warm-up; Decode Ways II layers wildcard logic and combinatorial counting. The acceptance rate of 31% reflects that jump. You need DP, but the transitions are messier because each state can branch into multiple paths. Most people who solve Decode Ways still struggle here.
What's the trick to not TLE with wildcards?+
Never recurse without memoization, and be smart about state. A '*' can represent 9 different digits (1-9) or 10 (0-9) depending on its position. You track the count of ways modulo some number, not the strings themselves. Bottom-up DP with careful transitions beats top-down if you're not confident in memoization.
Is this still asked at PhonePe or other companies?+
PhonePe is confirmed to ask it. Given the 31% acceptance and the algorithmic depth, it remains a legitimate hard interview question. It's not as common as easier DP strings, but it's the exact kind of problem that separates prep from understanding.
What are the most common mistakes?+
Forgetting that '0' can't stand alone, so '*' followed by a digit requires checking if that digit can form a valid two-digit code. Off-by-one errors in DP transitions. Incorrect modulo application. Not handling consecutive wildcards correctly. Many candidates also forget to validate two-digit codes before applying modulo.
How should I prepare for this specific problem?+
Master classic Decode Ways first, then add wildcard handling one step at a time. Draw out the state machine on paper: what transitions are valid from each position? Write the two-digit validation logic separately and test it. Practice modular arithmetic without mistakes. If live assessment hits this and your logic breaks, StealthCoder surfaces a clean solution in seconds.
Want the actual problem statement? View "Decode Ways II" on LeetCode →