Beats 100% users using C++ | Queue Using | Detailed solution
Intuition\nUsing queue from standard C++ library\n\n# Approach\n1. Create two queues of students and sandwiches\n2. And a count variable to check if is loop in 
# Intuition\nUsing queue from standard C++ library\n\n# Approach\n1. Create two queues of students and sandwiches\n2. And a count variable to check if is loop in left student\n3. If students in the queue cannot have their ordered sandwiches, it makes a loop. If it is a loop, just break and return the result\n4. Then implement the program like the given rules. \n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n\n![image.png](https://assets.leetcode.com/users/images/0c3ac90a-7683-4009-af74-3cce9825aa68_1712537403.9941149.png)\n\n# Code\n```\nclass Solution {\npublic:\n    int countStudents(vector<int>& students, vector<int>& sandwiches) {\n        queue<int> student, sandwich;\n        int isLoop = 0;\n        //create two queues of sandwiches and students\n        for(int i = 0; i < students.size(); i++)\n            student.push(students[i]);\n        for(int i = 0; i < sandwiches.size(); i++)\n            sandwich.push(sandwiches[i]);\n        \n        while(true)\n        {\n            if(isLoop == student.size()) break;\n//if one student come back to the queue, add isLoop by 1\n            if(student.front() != sandwich.front())\n            {\n                student.push(student.front());\n                student.pop();\n                isLoop++;\n            }\n            else\n            {//if a student takes his sandwich, just remove both of them \n                isLoop = 0;\n                student.pop();\n                sandwich.pop();\n            }\n        }\n        return student.size();\n        \n    }\n};\n```
['C++']