
Asked in Ola Cabs
Minimum Number Of Taps To Water Garden Problem Statement
You are required to determine the minimum number of taps that need to be opened to water an entire one-dimensional garden defined along the x-axis, which begins at 0 and concludes at N. There are N + 1 taps located at points [0, 1, 2, ..., N].
Given an integer N and an array 'ranges' of size N + 1, where the i-th tap can water the garden from (i - ranges[i]) to (i + ranges[i]), find the minimum number of taps to open to fully water the garden. Return -1 if it's impossible to water the entire garden.
Example:
Input:
T = 1
N = 5
ranges = [3, 4, 1, 1, 0, 0]
Output:
1
Explanation:
Opening the tap at position 0 covers positions [0, 6].
Constraints:
- 1 <= T <= 10
- 1 <= N <= 104
- 0 <= ranges[i] <= 100
Note:
You do not need to print anything; the output will be handled by the system.

Find the minimum number of taps to water an entire garden along the x-axis.
Iterate over the taps and find the farthest point each tap can reach.
Sort the taps based on their starting points and use a g...read more
Top Software Developer Interview Questions Asked at Ola Cabs
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Ola Cabs Software Developer


Reviews
Interviews
Salaries
Users

