Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many ways can the digit string 226 be decoded when 1 to 26 map to A to Z?

  1. A. 4
  2. B. 3
  3. C. 5
  4. D. 7

Correct answer: B. 3

Decode as 2-2-6 (BBF), 22-6 (VF), and 2-26 (BZ): three ways. The DP over prefixes adds the one-digit and two-digit cases.

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

Exams that ask this topic