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.)
- A. 4
- B. 3
- C. 2
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Keys 50, 30, 20, 10, 40, 70, 60 are inserted into an empty BST. An iterative inorder traversal pushes nodes while walking left and pops to…
- A course plan has prerequisites (a → b means a must come before b): 1→3, 2→3, 3→5, 4→5, 5→6, 2→4, 6→7. Any number of courses with all…
- Flights (directed, cost): 0→1 100, 1→2 100, 2→3 100, 0→2 500, 1→3 600, 0→3 900. What is the cheapest cost from 0 to 3 using AT MOST 1…
- What is the diameter (largest distance between any two nodes) of the weighted tree with edges 1–2 (3), 1–3 (4), 2–4 (2), 2–5 (6), 3–6 (5)…
- Running median with two heaps (a max-heap for the lower half, a min-heap for the upper half, sizes differing by at most 1, the lower half…
- Each array is a binary tree in level order (0-indexed, children at 2i + 1 and 2i + 2, all positions present). Which one is a valid BST?