We have a street with some bulbs each bulb can light up a certain amount of distance.
Distance a bulb can light up is given in array where ith index gives distance ith bulb can light up. If distance is negative it means bulb is falty. If distance is 0 bulb can light up its space but not enough to light up surrondings.
Need to find minumum number of light bulbs to turn on to light up whole street.
Ex : {-1, 2, 2, -1, 0, 0}
Ans: minimum number of bulbs to light up is 2. bulb at index 2 and bulb at index 5 (0-indexing).
Ex:{2, 3, 4, -1, 2, 0, 0, -1, 0}
Ans: -1 as it is not possible to light up bulb at index 7.
How to do this in polynomial time complexity? I can think of backtracking approach but it is exponential.