Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional
Problem: A 2D prefix-sum table is built for the grid [[1,2,3],[4,5,6],[7,8,9]]. What is the sum of the submatrix with rows 1–2 and columns 0–1 (0-indexed, inclusive)?
- A. 27
- B. 24
- C. 39
- D. 28
Correct answer: B. 24
With prefix sums P, the block sum is P[2][1] − P[0][1] = 27 − 3 = 24, i.e. 4 + 5 + 7 + 8. Forgetting to subtract row 0 gives 27, extending to column 2 gives 39, and shifting to columns 1-2 gives 28.
More Coding Interview Problems questions
- Problem: A sparse-table-free query: over the array [5, 2, 8, 1, 9, 3, 7], what is the minimum value on the range of indices [2, 5]…
- Problem: A Fenwick tree (binary indexed tree) over positions 1–8 starts with all zeros. The operations are: add 5 at position 3, add 4 at…
- Problem: Compute the 50th Fibonacci number F(50) with F(1) = F(2) = 1, modulo 1,000,000,007.
- Problem: Compute C(20, 10) modulo 1,000,000,007 (the binomial coefficient).
- Problem: How many prime numbers are there up to 100 (inclusive)?
- Problem: What is the LCM of the array [4, 6, 10, 15]?