1375. Bulb Switcher III
https://leetcode.com/problems/bulb-switcher-iii/

Last updated
https://leetcode.com/problems/bulb-switcher-iii/

Last updated
Input: light = [2,1,3,5,4]
Output: 3
Explanation: All bulbs turned on, are blue at the moment 1, 2 and 4.Input: light = [3,2,4,1,5]
Output: 2
Explanation: All bulbs turned on, are blue at the moment 3, and 4 (index-0).Input: light = [4,1,2,3]
Output: 1
Explanation: All bulbs turned on, are blue at the moment 3 (index-0).
Bulb 4th changes to blue at the moment 3.Input: light = [2,1,4,3,6,5]
Output: 3Input: light = [1,2,3,4,5,6]
Output: 6class Solution {
public:
int numTimesAllBlue(vector<int>& light) {
int res = 0;
for (int i = 0, r = 0; i < light.size(); ++i) {
r = max(r, light[i]);
if (i + 1 == r) ++res;
}
return res;
}
};