Description
There is a room with n bulbs labeled from 1 to n. All bulbs are off initially. You turn on exactly one bulb every moment. A bulb changes color to blue only when all bulbs to its left are on. Return the number of moments where all turned-on bulbs are blue.
Examples
light = [2,1,3,5,4]3At moments 2, 3, 5 all on bulbs are blue.
light = [1,2,3,4]4All bulbs are turned on in order from left to right. At moment 1: bulb 1 is on and blue (no bulbs to its left). At moment 2: bulbs 1,2 are on and both blue. At moment 3: bulbs 1,2,3 are on and all blue. At moment 4: bulbs 1,2,3,4 are on and all blue. Since bulbs are turned on sequentially, all turned-on bulbs are always blue at every moment.
light = [3,1,4,2]1At moment 1: bulb 3 is on but not blue (bulbs 1,2 to its left are off). At moment 2: bulbs 3,1 are on, only bulb 1 is blue. At moment 3: bulbs 3,1,4 are on, only bulb 1 is blue (bulb 3 can't be blue because bulb 2 is off). At moment 4: all bulbs 1,2,3,4 are on and all are blue. Only at the final moment are all turned-on bulbs blue.
Constraints
- •
n == light.length - •
1 ≤ n ≤ 5 * 10^4