Code RoomMinimum taps water garden
HardPrep Room Coding #1327

Minimum taps water garden

CodingAlgorithms & data structuresSenior–Staff~35 min

A garden runs along a line from point 0 to point n. There are n+1 taps at integer points 0..n; tap i has range ranges[i], meaning when open it waters the closed interval [i - ranges[i], i + ranges[i]]. Return the minimum number of taps to open so the entire garden [0, n] is watered, or -1 if it is impossible. Constraints: 1 <= n <= 10^4, 0 <= ranges[i] <= 100, len(ranges) == n + 1.

Implement
min_taps(n: int, ranges: list[int]) → int
Examples
in[5,[3,4,1,1,0,0]]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[5,[3,4,1,1,0,0]]1not run yetsample