package leetcode;

/**
 * https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/
 */
public class Problem1700 {
    public int countStudents(int[] students, int[] sandwiches) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1700 prob = new Problem1700();
        System.out.println(prob.countStudents(new int[]{1,1,0,0}, new int[]{0,1,0,1})); // 0
        System.out.println(prob.countStudents(new int[]{1,1,1,0,0,1}, new int[]{1,0,0,0,1,1})); // 3
    }
}

@@ -12,16 +12,46 @@
 tcode;%0A%0A
+import java.util.LinkedList;%0A%0A
 /**%0A * h
@@ -227,38 +227,119 @@
     
-// TODO%0A        return
+LinkedList%3CInteger%3E studentList = new LinkedList%3C%3E();%0A        int zeroCount = 0;%0A        int oneCount =
  0;%0A    
 %7D%0A%0A 
@@ -338,295 +338,879 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1700 prob = new Problem1700();%0A        System.out.println(prob.countStudents(new int%5B%5D%7B1,1,0,0%7D, new int%5B%5D%7B0,1,0,1%7D)); // 0%0A        System.out.println(prob.countStudents(new int%5B%5D%7B1,1,1,0,0,1%7D, new int%5B%5D%7B1,0,0,0,1,1%7D)); // 3
+for (int student : students) %7B%0A            if (student == 0) %7B%0A                zeroCount++;%0A            %7D else %7B%0A                oneCount++;%0A            %7D%0A            studentList.addLast(student);%0A        %7D%0A        int index = 0;%0A        while (index %3C sandwiches.length) %7B%0A            if ((zeroCount == 0 && sandwiches%5Bindex%5D == 0) %7C%7C%0A                (oneCount == 0 && sandwiches%5Bindex%5D == 1)) %7B%0A                break;%0A            %7D%0A            if (studentList.peekFirst() == sandwiches%5Bindex%5D) %7B%0A                int student = studentList.removeFirst();%0A                if (student == 0) %7B%0A                    zeroCount--;%0A                %7D else %7B%0A                    oneCount--;%0A                %7D%0A                index++;%0A            %7D else %7B%0A                studentList.addLast(studentList.removeFirst());%0A            %7D%0A        %7D%0A        return studentList.size();
 %0A   

Solve problem 1700