Decode Ways
Reported by candidates from DE Shaw's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Decode Ways at DE Shaw, reported September 2026, looks like a string problem but it's really a counting problem in disguise. Strip the letters away and you're counting ways to cut a digit string into pieces of length one or two, where each piece has to be a valid code. That's a Fibonacci-flavored DP with a couple of nasty zero cases. If you've seen it before, it's ten minutes. If you blank on the zeros, it eats your whole OA. StealthCoder sits invisibly as a safety net if your head goes empty mid-assessment.
The problem
A message is encoded by mapping letters to numbers: A -> 1, B -> 2,..., Z -> 26. Given a numeric string digits, return the number of different ways it can be decoded into letters. A one-digit code is valid when it is between 1 and 9. A two-digit code is valid when it is between 10 and 26. Function countDecodings(digits: String) → int Examples Example 1 digits = "2116" return = 5 The valid decodings split the string as 2,1,1,6, 21,1,6, 2,11,6, 2,1,16, and 21,16. Constraints 1 <= digits.length <= 10^5 digits consists of numeric characters. The number of valid decodings is guaranteed to fit in a signed 32-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Define dp[i] as the number of ways to decode the first i characters. Start with dp[0] = 1. For each position, if the current digit is 1-9, add dp[i-1]. If the previous two digits form a number from 10 to 26, add dp[i-2]. That's the whole recurrence, and you only need two rolling variables, so space is O(1) and time is O(n) for n up to 10^5. The pitfall is zero. A lone '0' is invalid, and '30' or '00' kill the count completely, so the answer can drop to 0. Also don't treat '06' as a valid two-digit code. Check the numeric range 10-26, not just the length. Recursion without memoization will time out at this input size. If the recurrence slips away during the live OA, StealthCoder is the hedge that hands you the clean rolling-variable version.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Decode Ways cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as decode ways. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass DE Shaw's OA.
DE Shaw reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Decode Ways FAQ
What's the trick in Decode Ways?+
It's a DP where each position depends on the previous two. Add the count from one step back if the single digit is 1-9, and add the count from two steps back if the pair is 10-26. Handle zeros explicitly and the rest falls out.
How hard is this DE Shaw question really?+
Medium difficulty. The idea is short, but the zero edge cases trip people up. With n up to 10^5 you also need linear time, so naive recursion without memoization fails. Most candidates who know the recurrence finish quickly.
Which edge cases should I test first?+
Test strings with zeros: '0' returns 0, '10' returns 1, '100' returns 0, '06' returns 0, and '27' returns 1. Also test a single digit and a long string of 1s. Those catch nearly every bug in this problem.
Can I use O(1) space?+
Yes. You only ever read dp[i-1] and dp[i-2], so keep two variables and roll them forward. Start with prev2 = 1 and prev1 = 1 if the first digit is nonzero, else return 0. It's a small change that interviewers like.
How do I prepare for this in 48 hours?+
Write the DP from scratch twice without looking, then run the zero cases by hand. Also do Climbing Stairs if the recurrence feels shaky, since it's the same shape. Don't memorize code. Memorize the two conditions that add to the count.