Minimum Number of Taps to Water a Garden
Updated
Problem statement
A one-dimensional garden covers the closed interval [0, n]. Tap i waters [i - ranges[i], i + ranges[i]], clipped to the garden.
Return the minimum number of taps needed to water every point in [0, n]. Return -1 if complete coverage is impossible.
Function
minimumTaps(n: int, ranges: int[]) → intExamples
Example 1
n = 5ranges = [3,4,1,1,0,0]return = 1Tap 1 covers the whole interval [0,5].
Example 2
n = 3ranges = [0,0,0,0]return = -1No tap covers a positive-length interval.
Constraints
1 <= n <= 100000ranges.length == n + 10 <= ranges[i] <= n
More Goldman Sachs Online Assessment questions
- Maximum Ones After K OperationsOA · Seen Nov 2026
- Palindrome CounterOA · Seen Oct 2026
- Longest Palindromic SubsequenceOA · Seen Oct 2026
- Count Redundant File BackupsOA · Seen Oct 2026
- Minimum Distinct Prefix CostOA · Seen Oct 2026
- Merge Overlapping IntervalsOA · Seen Sep 2026
- Data ReorganizationOA · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsOA · Seen Jul 2026
- Find the Winner of an Array GameOA · Seen Jun 2026
Similar questions at other companies
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Split Array Largest SumAuxoAI · OA
- Get Minimum IncrementIBM · OAIBM interview questions
- Find Minimum Cost to Shift MachinesCisco · OACisco interview questions
- Maximum Income from Asset TradingJefferies · OA
- Best Time to Buy and Sell StockFlexTrade · OAFlexTrade interview questions
- Maximum Even-Sum Neighboring PairsDRW · OADRW interview questions
- Minimize Total Input Cost (for LTMS)Salesforce · OASalesforce interview questions
- Maximize Protected City PopulationAmazon · OA
- Network FormationPalantir · OAPalantir interview questions