Uber ATG Toronto
Q: We have a 1-D garden that we're trying to water. This garden can be envisioned with a 1-D array of N entries: there's a tree at every location of that array. At location i
, there is a sprinkler with the range of m[i]
. A range of 1 means that the sprinkler can only water the tree at its own location. A range of 2 would mean that the sprinkler can water itself, and one tree from either of its sides: (i.e. locations: i-1
, i
, i+1
).
- Given an array B of boolean values, where each entry is true if the sprinkler at that location is on, and is false if the sprinkler is off, write me a function that returns if the garden is fully getting watered.
- Write me a function that minimizes the number of sprinklers turned on such that the entire garden is watered: it should return indices of sprinklers that have to be turned on.