C++ Simple and Clean Explained Solution, 0ms Faster than 100%
Count how many of each type the students want.\nThen loop through the sandwiches, and check if there\'s a student who wants each sandwich.\nWhen we get to a san
Count how many of each type the students want.\nThen loop through the sandwiches, and check if there\'s a student who wants each sandwich.\nWhen we get to a sandwich that nobody wants, we return n - k (The remaining students in the line).\n```\nclass Solution {\npublic:\n    int countStudents(vector<int>& students, vector<int>& sandwiches) {\n        int n = sandwiches.size();\n        vector<int> student_count(2, 0);\n        for (auto s : students) student_count[s]++;\n       \n        for (int i = 0; i < n; i++) {\n            student_count[sandwiches[i]]--;\n            if (student_count[sandwiches[i]] < 0) return n - i;\n        }\n        \n        return 0;\n    }\n};\n```\n**Like it? please upvote!**
['C']