BEATS 100% ON BOTH RUNTIME AS WELL AS MEMORY||C++||SIMPLE AND EASY CODE||O(n)||
\n\n# Approach\njust check whether the top element of the sandwiches is needed by any student or not.\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complex
\n\n# Approach\njust check whether the top element of the sandwiches is needed by any student or not.\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int countStudents(vector<int>& students, vector<int>& sandwiches) {\n        int countsquare=0;\n        int countcircle=0;\n        int size=students.size();\n\n        for(int i=0;i<size;i++){\n            if(students[i]==0){\n                countcircle++;\n            }else{\n                countsquare++;\n            }\n        }\n        while(size>0){\n            //students are in queue\n            if(students[0]==sandwiches[0]){\n                if(sandwiches[0]==0){\n                    countcircle--;\n                }else{\n                    countsquare--;\n                }\n                students.erase(students.begin());\n                sandwiches.erase(sandwiches.begin());\n                size--;\n            }\n            //agr same nhi hai\n            if(students[0]!=sandwiches[0]){\n                if(sandwiches[0]==0){\n                    if(countcircle==0){\n                        return size;\n                    }\n                }else{\n                    if(countsquare==0){\n                        return size;                        \n                        \n                    }\n                }\n            }\n\n        if(students[0]!=sandwiches[0]){\n            students.push_back(students[0]);\n            students.erase(students.begin());\n        }\n     \n        }\n        return 0;\n     }\n};\n```
['C++']