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?
- A. 12
- B. 3
- C. 8
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- For the array [3, -7, 4, -2, 5, -9, 6, 1], you may delete at most ONE element (the rest keep their order). Then you take a non-empty…
- Array [2, 3, 1, 1, 4, 2, 1, 3, 1, 2]: from index i you may jump to any index in the range i+1 ... i+arr[i]. You start at index 0 and want…
- You split the array [1, 15, 7, 9, 2, 5, 10] into contiguous non-empty segments, each of length at most 3. A segment contributes (its…
- What is the maximum product of a non-empty contiguous subarray of [-2, 3, -4, 0, -1, 5, -3, -2]?
- How many binary strings of length 12 contain no three consecutive 1s and end with the digit 0?
- Coins of denominations 1, 3 and 4 are available in unlimited supply. What is the minimum number of coins needed to make exactly 6?