package leetcode;

/**
 * https://leetcode.com/problems/bulb-switcher-iii/
 */
public class Problem1375 {
    public int numTimesAllBlue(int[] light) {
        int answer = 0;
        Color[] colors = new Color[light.length];
        for (int i = 0; i < light.length; i++) {
            colors[i] = Color.WHITE;
        }
        int yellowCount = 0;
        for (int l : light) {
            colors[l - 1] = Color.YELLOW;
            yellowCount++;
            int i = 0;
            while (i < light.length && colors[i].on) {
                if (colors[i] == Color.YELLOW) {
                    yellowCount--;
                }
                colors[i] = Color.BLUE;
                i++;
            }
            if (yellowCount == 0) {
                answer++;
            }
        }
        return answer;
    }

    private enum Color {
        WHITE(false),
        YELLOW(true),
        BLUE(true);

        private final boolean on;

        Color(boolean on) {
            this.on = on;
        }
    }

    public static void main(String[] args) {
        Problem1375 prob = new Problem1375();
        System.out.println(prob.numTimesAllBlue(new int[]{2,1,3,5,4})); // 3
        System.out.println(prob.numTimesAllBlue(new int[]{3,2,4,1,5})); // 2
        System.out.println(prob.numTimesAllBlue(new int[]{4, 1, 2, 3})); // 1
        System.out.println(prob.numTimesAllBlue(new int[]{2,1,4,3,6,5})); // 3
        System.out.println(prob.numTimesAllBlue(new int[]{1,2,3,4,5,6})); // 6
        System.out.println(prob.numTimesAllBlue(new int[]{3,2,1})); // 1
        System.out.println(prob.numTimesAllBlue(new int[]{3,1,2})); // 1
    }
}

@@ -366,32 +366,234 @@
 nt l : light) %7B%0A
+            if (l - 2 %3E= 0 && colors%5Bl - 2%5D == Color.BLUE && yellowCount == 0) %7B%0A                colors%5Bl - 1%5D = Color.BLUE;%0A                answer++;%0A                continue;%0A            %7D else %7B%0A    
             colo
@@ -618,16 +618,20 @@
 YELLOW;%0A
+    
         
@@ -645,24 +645,38 @@
 lowCount++;%0A
+            %7D%0A
             
@@ -1321,16 +1321,18 @@
 1375();%0A
+//
         
@@ -1392,32 +1392,34 @@
 ,3,5,4%7D)); // 3%0A
+//
         System.o
@@ -1543,15 +1543,12 @@
 %5D%7B4,
- 
 1,
- 
 2,
- 
 3%7D))
@@ -1546,32 +1546,34 @@
 ,1,2,3%7D)); // 1%0A
+//
         System.o
@@ -1635,16 +1635,18 @@
 ); // 3%0A
+//
         
@@ -1716,16 +1716,18 @@
 ); // 6%0A
+//
         
@@ -1787,24 +1787,26 @@
 ,1%7D)); // 1%0A
+//
         Syst

Update problem 1375