← All problems

Decode Ways

Medium dynamic programmingstrings LeetCode ↗
A message is encoded by mapping 1->'A', 2->'B', ..., 26->'Z'. Given a digit string, count how many ways it can be decoded. Watch out for '0', which cannot stand alone.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(1)

Common pitfalls

  • Treating '0' as standalone valid
  • Missing the '10'/'20' pair case

Your solution

Log in to save your code and track progress.