Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: How many sequences made of the numbers 1 and 2 sum to 8, where no two 2s are adjacent (order matters)?
- A. 34
- B. 7
- C. 5
- D. 19
Correct answer: D. 19
A DP on whether the last part was a 2 gives 19 sequences for sum 8. Ignoring the rule gives F(9) = 34, banning adjacent 1s instead gives 7, and 5 counts unordered multisets.
More Coding Interview Problems questions
- Problem: From the array [−10, −10, 5, 2], pick three numbers (distinct positions) to maximise their product. What is the maximum product?
- Problem: The edit distance (insert, delete, replace, each cost 1) between "horse" and "ros" is computed. What is it?
- Problem: What is the length of the longest common subsequence of the three strings "abc", "abd" and "ab"?
- Problem: Split the array [7, 2, 5, 10, 8] into 2 contiguous non-empty parts so that the largest part sum is as small as possible. What is…
- Problem: A 3×3 spiral is filled starting with 1 at the top-left and moving right, then down, then left, then up, spiralling inward. What…
- Problem: Count the unordered pairs (x, y) with 1 ≤ x < y ≤ 7 for which x OR y equals 7.