C++ Simulation with Queue
Intuition\nI could not think of a super clever way to solve this, so I decided to simulate.\n\n# Approach\n1) Use a queue to hold all of the students.  \n\n1) F
# Intuition\nI could not think of a super clever way to solve this, so I decided to simulate.\n\n# Approach\n1) Use a queue to hold all of the students.  \n\n1) For each sandwich, we will try every one in the queue until we find a match.\n    a) if a match is found, that person is removed from the queue, and we move onto the next sandwich.\n    b) if no match is found, then that person gets re-inserted into the queue.\n\n1) Once we have tried everyone in the queue once, if no one was removed from the queue, that means that we did not find a match.  We can return the size of the queue as the answer.\n\n1) If we are able to match all the sandwiches with people, then we can return 0.\n\n1) Tune into my stream 3 times a week to practice algorithms with me.  Schedule in profile\n\n# Complexity\n- Time complexity:\n- $$O(n^2)$$ (i think)\n\n- Space complexity:\n- $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int countStudents(vector<int>& students, vector<int>& sandwiches) {\n        queue<int> q;\n\n        for(int x : students) {\n            q.push(x);\n        }\n        int n = students.size();\n\n        for(int i = 0; i < n; i++) {\n            int q_size = q.size();\n            bool keep_going = true;\n            for(int j = 0; j < q_size && keep_going; j++) {\n               \n                int next_pref = q.front();\n                q.pop();\n\n                if(next_pref == sandwiches[i]) {\n                    keep_going = false;\n                    break;\n                } else {\n                    q.push(next_pref);\n                }\n                \n            }\n            if(q.size() == q_size) {\n                return q_size;\n            }\n        }\n\n        return 0;\n    }\n};\n```
['C++']