Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 C
Problem: How many contiguous subarrays of [7, 2, 9, 4, 1, 8, 3, 5, 6, 10] have a sum divisible by 7?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
Prefix sums modulo 7 with a count of seen residues: two prefixes with equal residue bracket a divisible-by-7 subarray. The empty prefix (residue 0) must be counted initially.
More Coding Interview Problems questions
- Problem: Floyd–Warshall is run on 4 vertices with directed edges 0→1 (3), 1→2 (4), 0→2 (9), 2→3 (1), 3→0 (2), 1→3 (5). Unreachable pairs…
- Problem: On a 6×6 grid, a robot starts at the top-left corner and moves only right or down to the bottom-right corner. The cells (1,2)…
- Problem: Place 4 non-attacking rooks on a 4×4 board (no two share a row or column) such that none is on a forbidden cell. Forbidden cells…
- Problem: In a grid of 0s and 1s, a connected region is a group of 1-cells that are connected when moving to 8 neighbours (up, down, left…
- Problem: A rooted tree is given by parent array p = [-1, 0, 0, 1, 1, 2, 5, 5, 3] for nodes 0–8 (node 0 is the root). How many nodes are at…
- Problem: A max-heap starts with the values 9, 8, 6, 5, 4, 3, 1 (inserted in that order). Then three times in succession: pop the maximum…