C++ || Using Deque
\n# Code\n\nclass Solution {\npublic:\n    int countStudents(vector<int>& stu, vector<int>& sand) {\n        stack<int>st;\n        deque<int>q;\n        for(in
\n# Code\n```\nclass Solution {\npublic:\n    int countStudents(vector<int>& stu, vector<int>& sand) {\n        stack<int>st;\n        deque<int>q;\n        for(int i=sand.size()-1;i>=0;i--)\n        st.push(sand[i]);\n        for(int i=stu.size()-1;i>=0;i--)\n        q.push_front(stu[i]);\n        int s =5000;\n        while(s>0){\n        if(q.front() == st.top())\n        {\n            q.pop_front();\n            st.pop();\n        }\n\n        else\n        {\n            int temp = q.front();\n            q.pop_front();\n            q.push_back(temp);\n        }\n       s--;\n     if(q.empty())\n        break;\n     }\n   \n      return st.size();\n    }\n};\n```
['C++']