[Java/C++/Python] Easy and Concise
Explanation\nCount students\' preference of food to count\nNow we iterate the food one by one,\nand see if any one in the left students queue will take it.\n\nW
# **Explanation**\n`Count` students\' preference of food to `count`\nNow we iterate the food one by one,\nand see if any one in the left students queue will take it.\n\nWe stop at `sandwiches[k]` if no one wants it,\nthen `n - k` students are unable to eat.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(2)`\n<br>\n\n**Java:**\n```java\n    public int countStudents(int[] A, int[] B) {\n        int count[] = {0, 0}, n = A.length, k;\n        for (int a: A)\n            count[a]++;\n        for (k = 0; k < n && count[B[k]] > 0; ++k)\n            count[B[k]]--;\n        return n - k;\n    }\n```\n\n**C++:**\n```cpp\n    int countStudents(vector<int>& A, vector<int>& B) {\n        int count[] = {0, 0}, n = A.size(), k;\n        for (int a : A)\n            count[a]++;\n        for (k = 0; k < n && count[B[k]] > 0; ++k)\n            count[B[k]]--;\n        return n - k;\n    }\n```\n\n**Python:**\n```py\n    def countStudents(self, A, B):\n        count = collections.Counter(A)\n        n, k = len(A), 0\n        while k < n and count[B[k]]:\n            count[B[k]] -= 1\n            k += 1\n        return n - k\n```\n
[]