1-bit and 2-bit Characters (LeetCode 717)

Insight

Scan left to right: 0 advances 1, 1 advances 2. Check whether the final character is reached as a lone 0.

Tip

Do not reverse-engineer from the end unless you prove the unique decoding.

Follow-up

Discuss why greedy left-to-right works for this encoding.

See Linkjob.ai.