✅Beginner friendly Intuition C++(with comments) O(1) Space, O(n) Time without Queue✅
Intuition:\n The order of students doesn\'t matter.\n For example, if there is a square sandwich present at the top of the stack and if there is student present
# **Intuition:**\n* The order of students doesn\'t matter.\n* For example, if there is a square sandwich present at the top of the stack and if there is student present in the queue who prefers square sandwich, then until his turn comes all the students will go to the back and he will eat that sandwich.\n* But if a situation comes where there is a square sandwich on the top but there is no student who prefers it, that is all the students in queue prefer circular sandwich then all of them will be unable to eat any sandwich. Same for circular sandwiches as well.\n* Thus we only need to check when that situation will come, if it never comes then all the student will be able eat sandwiches.\n\n# **Code:**\n\n```\nclass Solution {\npublic:\n    int countStudents(vector<int>& students, vector<int>& sandwiches) {\n\t// number students who prefer square and circular sandwiches\n        int square = 0, circular = 0;\n        for (int i = 0 ; i < students.size(); i++) {\n\t\t// Counting the total number of students \n            square += (students[i] == 1);\n            circular += (students[i] == 0);\n        }\n        for (int i = 0; i < sandwiches.size(); i++) {\n            if (sandwiches[i] == 0) {\n\t\t\t// if the sandwich is circular and there are students left who like circular sandwiches\n\t\t\t// then one of them will eat it so the count reduces by one\n                if (circular > 0) circular--;\n\t\t\t\t// if there are no circular sandwiches lovers left, it means there are only square sandwiches lover left\n\t\t\t\t// and since the sandwich on the top of the stack is circular, they will never be able to eat it \n\t\t\t\t// and go hungry\n                else return square;\n            }\n            else {\n                if (square > 0) square--;\n                else return circular;\n            }\n        }\n\t\t// all students were able to eat\n        return 0;\n    }\n};\n```
['Queue', 'C']