Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT

Each digit string maps to letters with 1 to A ... 26 to Z. The string "2262012" is split into groups of one or two digits, and each group must map to a letter (so '0' alone is not a letter and '01' is not allowed). How many different decodings are there?

  1. A. 12
  2. B. 3
  3. C. 8
  4. D. 6

Correct answer: D. 6

Use dp[i] = (dp[i-1] if the single digit is not 0) + (dp[i-2] if the last two digits form 10 to 26). A lone '0' contributes nothing, so treating it as a valid letter overcounts.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic