Data Structures & AlgorithmsHardICPC regional · DP round
Problem: A product of 11 matrices A1 * A2 * ... * A11 is evaluated by choosing a full parenthesisation. How many different parenthesisations are possible?
- A. 4862
- B. 58786
- C. 16796
- D. 16384
Correct answer: C. 16796
A product of n matrices has Catalan(n - 1) parenthesisations, so 11 matrices give Catalan(10) = 16796. Using Catalan(9) = 4862 is the off-by-one trap.
More Coding Interview Problems questions
- Problem: n = 10 people stand in a circle and every 3rd person is removed until one remains (counting starts at person 1 and the removed…
- Problem: Compute F(100) mod 1000 where F(0) = 0, F(1) = 1 and F(n) = F(n-1) + F(n-2). python def mul(A, B, m): return [[sum(A[i][k]…
- Problem: Count the inversions of the array [3, 1, 4, 1, 5, 9, 2, 6], where an inversion is a pair of positions i < j with a[i] > a[j]…
- Problem: Huffman coding is applied to symbol frequencies 5, 9, 12, 13, 16, 45, always merging the two smallest weights. What is the total…
- Problem: Find the maximum of every window of size 3 in the array below, printing the list of window maxima. python from collections import…
- Problem: Compute the Z-array (z[i] = length of the longest common prefix of s and s[i:], with z[0] set to 0) for s = 'aabxaab'. python def…