|
1 | 1 | packagecom.fishercoder.solutions; |
2 | 2 |
|
3 | | -/** |
4 | | - * 1375. Bulb Switcher III |
5 | | - * |
6 | | - * There is a room with n bulbs, numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off. |
7 | | - * At moment k (for k from 0 to n - 1), we turn on the light[k] bulb. A bulb change color to blue only if it is on and all the previous bulbs (to the left) are turned on too. |
8 | | - * Return the number of moments in which all turned on bulbs are blue. |
9 | | - * |
10 | | - * Example 1: |
11 | | - * Input: light = [2,1,3,5,4] |
12 | | - * Output: 3 |
13 | | - * Explanation: All bulbs turned on, are blue at the moment 1, 2 and 4. |
14 | | - * |
15 | | - * Example 2: |
16 | | - * Input: light = [3,2,4,1,5] |
17 | | - * Output: 2 |
18 | | - * Explanation: All bulbs turned on, are blue at the moment 3, and 4 (index-0). |
19 | | - * |
20 | | - * Example 3: |
21 | | - * Input: light = [4,1,2,3] |
22 | | - * Output: 1 |
23 | | - * Explanation: All bulbs turned on, are blue at the moment 3 (index-0). |
24 | | - * Bulb 4th changes to blue at the moment 3. |
25 | | - * |
26 | | - * Example 4: |
27 | | - * Input: light = [2,1,4,3,6,5] |
28 | | - * Output: 3 |
29 | | - * |
30 | | - * Example 5: |
31 | | - * Input: light = [1,2,3,4,5,6] |
32 | | - * Output: 6 |
33 | | - * |
34 | | - * Constraints: |
35 | | - * n == light.length |
36 | | - * 1 <= n <= 5 * 10^4 |
37 | | - * light is a permutation of [1, 2, ..., n] |
38 | | - * */ |
39 | 3 | publicclass_1375 { |
40 | 4 | publicstaticclassSolution1 { |
41 | 5 | publicintnumTimesAllBlue(int[]light) { |
|