Minimum Number of Taps to Open to Water a Garden
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A one-dimensional garden spans the points 0 to n. There are n + 1 taps, one at each integer point i. If tap i is opened it waters the closed interval [i - ranges[i], i + ranges[i]] (a tap with range 0 waters nothing beyond a single point, which does not help cover any length).
Return the minimum number of taps to open so that the whole interval [0, n] is watered, or -1 if that is impossible. Watered intervals only need to touch: [0, 2] and [2, 5] together cover [0, 5].
Examples
Constraints
- 1 <= n <= 10^4
- ranges.length == n + 1
- 0 <= ranges[i] <= 100
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.