Simple solution by using Deque DS
Intuition\nThe task description clearly describes the path to resolve the problem.\n\n\n# each student can take a sandwich \n# according to it\'s index (that\'s
# Intuition\nThe task description clearly describes the path to resolve the problem.\n\n```\n# each student can take a sandwich \n# according to it\'s index (that\'s 1 OR 0)\n# from sandwiches stack\n\n# the simplest example and pseudocode\nsandwiches = [1, 0, 1]\nstudents = [0, 1, 1]\n\n# while sandwiches\n# i = 0 => student == students[i] == 0\n# student != sandwiches[0] => he goes to the end \n\nsandwiches = [1, 0, 1]\nstudents = [1, 1, 0]\n\n# i = 1 => student == students[i] == 1\n# student == sandwiches[0] => he eats the sandwich and leaves the q\n\nsandwiches = [0, 1]\nstudents = [1, 0]\n\n# and so on \n```\n\n# Approach\n1. convert list of `students` and `sandwiches` into `deque` (though it\'s not necessary because of small size of data)\n2. then check, if the student can eat the sandwich, that\'s in the top of the stack, or move the student to the end of the stack, or **if the q is STUCK**, and there\'re no available permutations i.e.\n```\n# nobody can eat 0-sandwich in the q\nsandwiches = [0, 1, 1]\nstudents = [1, 1, 1]\n``` \n3. return remained amount of students\n\n# Complexity\n- Time complexity: **O(n^2)** in the worst case, because of iterating `n * n` students at all \n\n- Space complexity: **O(n)** because of converting lists into `deques`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def countStudents(self, students: list[int], sandwiches: list[int]) -> int:\n        students = deque(students)\n        sandwiches = deque(sandwiches)\n        \n        while sandwiches:\n            student = students[0]\n            \n            if student == sandwiches[0]:\n                students.popleft()\n                sandwiches.popleft()\n            else:\n                if sandwiches[0] not in students:\n                    break\n\n                students.popleft()\n                students.append(student)\n\n        return len(students)\n    \n    \n```
['Stack', 'Queue', 'Python3']