Data Structures & AlgorithmsHardInfosys · Wipro pattern

Digits map to letters A = 1 … Z = 26. In how many ways can the string '2263' be decoded? (dp over prefixes; a pair counts only if it is between 10 and 26.)

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

Correct answer: B. 3

Decodings: 2-2-6-3, 22-6-3, 2-26-3. '63' is above 26, so the last two digits cannot pair. dp: 1, 1, 2, 3, 3. Counting '63' as a pair gives 4 or more.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic