Data Structures & AlgorithmsHardICPC regional · TCS NQT
Problem: How many ways are there to write 20 as an ordered sum of parts from {2, 3, 5}?
- A. 11
- B. 309
- C. 628
- D. 448
Correct answer: D. 448
f(n) = f(n−2) + f(n−3) + f(n−5) with f(0) = 1 gives f(20) = 448. Unordered multisets give 11, f(19) = 309 is one index short, and f(21) = 628 one too far.
More Coding Interview Problems questions
- Problem: The sequence a0 = 0 and a(n) = a(n−1) + (n mod 3) for n ≥ 1 is defined. What is a(30)?
- Problem: A square matrix 4×4 has entry (i, j) equal to (i + 2j) mod 5. What is the sum of the entries on the main diagonal?
- Problem: The sum of the squares of the first 15 natural numbers, reduced modulo 7, is what value?
- Problem: Consider the array [3, 7, 4, 9, 2, 8, 5]. Two selection rounds are performed: first pick the largest value and remove it, then…
- Problem: Dictionary: a list of words is ["cat", "dog", "bat", "dig"]. Words are grouped by changing exactly one letter (Hamming distance…
- Problem: Starting at (0,0), a robot moves on an infinite grid using the string "UURDDLLUR" (U = up, D = down, L = left, R = right). The…