FastPrepMinimum Number of Taps to Water a Garden
Problems/Minimum Number of Taps to Water a Garden

Minimum Number of Taps to Water a Garden

Goldman Sachs logoGoldman Sachs● HardFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Goldman Sachs HackerRank assessment report links the exact Minimum Number of Taps to Open to Water a Garden exercise and says the test cases matched. This practice version is an approximately 99% match.

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[]) → int

Examples

Example 1

n = 5ranges = [3,4,1,1,0,0]return = 1

Tap 1 covers the whole interval [0,5].

Example 2

n = 3ranges = [0,0,0,0]return = -1

No tap covers a positive-length interval.

Constraints

  • 1 <= n <= 100000
  • ranges.length == n + 1
  • 0 <= 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
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public int minimumTaps(int n, int[] ranges) {
      // write your code here
    }
}
Checking account…