Data Structures & AlgorithmsHardTCS NQT Digital · ICPC regional
Problem: In how many ways can the number 12 be written as an ordered sum of parts each equal to 1, 2 or 3 (so 1+2+... and 2+1+... are different)?
- A. 927
- B. 19
- C. 233
- D. 504
Correct answer: A. 927
Ordered sums follow the tribonacci recurrence f(n) = f(n − 1) + f(n − 2) + f(n − 3) with f(0) = 1, giving f(12) = 927. Counting unordered partitions gives 19, allowing only parts 1 and 2 gives F(13) = 233, and f(11) = 504 is an off-by-one.
More Coding Interview Problems questions
- Problem: Trains arrive at times 900, 940, 950, 1100, 1500, 1800 and depart at 910, 1200, 1120, 1130, 1900, 2000 (all as 24-hour clock…
- Problem: The fractional knapsack has capacity 50 and items (value, weight): (60, 10), (100, 20), (120, 30). Items may be taken…
- Problem: Huffman coding is applied to the frequencies 5, 9, 12, 13, 16, 45 by repeatedly merging the two smallest values (the merged value…
- Problem: The union of the intervals [1, 5], [4, 8], [10, 12], [11, 15], [20, 22] covers some integer points. How many integers lie in the…
- Problem: Given the intervals [1,4], [2,6], [3,5], [5,8], [7,9], [8,10] (closed, integer endpoints), what is the largest number of…
- Problem: A functional graph has n = 9 nodes where node i points to f(i) given by the list [1, 2, 0, 4, 5, 3, 3, 6, 7] (node i has exactly…