Decode Ways
ways[i] adds ways[i-1] when the digit is not 0 and ways[i-2] when the pair before it lies in 10..26.
Decision · step 2 of 7DP in One Row: Decode ways of 11106
Digit 1 is 1. Alone it is letter A, so add ways[0] = 1. There is no digit before it for a pair. ways[1] = 1.
What you will see
Each position checks one and two characters back.
Cost
| Best | O(n) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Table cells announce their state and value; each step announces which cells were read and the value written.
Reduced motion: Dependency arrows appear statically and the cell value crossfades.
Before this
Taught by the same lesson
DP in One Row covers these too, in the same run.