As reported: D. E. Shaw SDE intern online assessment (on campus, 2025): one of three DSA problems, given as Codeforces 1927G.
A horizontal strip has n cells numbered 1..n. Cell i holds a paint charge of size a[i]. A charge can be used at most once, in one of two ways:
- to the left: paint cells
max(i − a[i] + 1, 1) … i; - to the right: paint cells
i … min(i + a[i] − 1, n).
A cell may be painted several times. Return the minimum number of charges needed to paint every cell.
Example 1
a = [1,2,1]
Output: 2
Use charge 2 to the left (cells 1–2) and charge 3 (cell 3).
Example 2
a = [2,1,2,1]
Output: 2
Charge 1 to the right paints 1–2, charge 3 to the right paints 3–4.
Constraints: 1 ≤ n ≤ 100; 1 ≤ a[i] ≤ n.
Code runner format: one JSON value per line: a (the charges, cell 1 first). Implement minCharges(a).