Minimum Number of Taps to Open to Water a Garden

Hard · Greedy · about 25 minutes

Asked at Google, Amazon, Microsoft, Meta.

A garden spans [0, n] with taps at points 0..n; tap i waters [i - ranges[i], i + ranges[i]] when open. Return the minimum number of taps to water the whole garden, or -1 if impossible.

Related guides