count+ loop||0ms Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nCount the numbers how many sandwitches of different types students want to eat\nUse a l
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCount the numbers how many sandwitches of different types students want to eat\nUse a loop to see whether there are enough sandwitches of those types for eating.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use count function to find the numbers of the sandwitches for the 2 types  students want; store them in an array p( where p[x] denotes the number for type x for x=0,1)\n2. Use a loop to transverse the array sandwitches do the following\n```\nif (p[x]==0) return p[1-x];\np[x]--;\n```\n3. If the loop is through. return 0;\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n# Code||0ms Beats 100%\n```\n#pragma GCC optimize("O3", "unroll-loops")\nclass Solution {\npublic:\n    int countStudents(vector<int>& students, vector<int>& sandwiches) {\n        int n=students.size(), p[2]={0};\n        p[0]=count(students.begin(), students.end(), 0), p[1]=n-p[0];\n        for (int x: sandwiches){\n            if (p[x]==0) return p[1-x];\n            p[x]--;\n        }\n        return 0;\n    }\n};\n\n```
['Array', 'C++']