AlgoScope

Decode Ways

Algorithmintermediate1D Dynamic Programming

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
012345digitways1✓110611

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.

Open in the player →or start at step 2

What you will see

Each position checks one and two characters back.

How dp in one row works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(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.