There are N light bulbs that are placed on a straight wire.
Each bulb has a switch associated with it, which turns it on or off.
There is one caveat though, turning a bulb on or off will change the state of all the bulbs to its right too.
What's the minimum number of switch toggles needed to turn all the bulbs on.
0 represents the off state and
1 represents the on state.
a = [0, 0, 0, 1]
answer = 2
We switch the bulb at index 0 and 3.
We can solve this problem using the greedy approach.
It can be observed that moving from left to right or right to left doesn't make a difference to the final number of toggles needed.
1. Start from the left and move towards right in the array.
2. If the current value is 0, we need to toggle this bulb.
3. Store that all the subsequent bulbs must be flipped.
4. If current value is 1, continue towards right.