Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
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 position 7, add 2 at position 3, add −1 at position 5. What is the prefix sum of the first 6 positions?
- A. 10
- B. 4
- C. 7
- D. 6
Correct answer: D. 6
Position 3 holds 5 + 2 = 7 and position 5 holds −1, so the prefix sum of positions 1-6 is 7 − 1 = 6 (position 7 lies outside). Including position 7 gives 10, letting the second add overwrite position 3 gives 4, and forgetting the −1 gives 7.
More Coding Interview Problems questions
- 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]?
- Problem: Count the pairs (i, j) with i < j in the array [1, 2, ..., 10] whose sum is divisible by 4.
- Problem: Find the majority element (appearing more than half the time) of [2, 2, 1, 1, 1, 2, 2] using the Boyer–Moore voting algorithm…