✅✅🔥 Beats 98.93% || Extra Easy Solution with Explanation.
\uD83D\uDC4D Upvote if you enjoyed the solution! \uD83D\uDC4D\n# Intuition:\nWe have a queue of students with their sandwich preferences and a stack of sandwich
**\uD83D\uDC4D Upvote if you enjoyed the solution! \uD83D\uDC4D**\n# Intuition:\nWe have a queue of students with their sandwich preferences and a stack of sandwiches to be served. The goal is to serve sandwiches to students based on their preferences. If a student\'s preferred sandwich is available, serve it; otherwise, move to the next student. The process stops when all sandwiches are served or when there are no more students to serve.\n\n# Approach:\nCount the number of students preferring each type of sandwich.\nServe sandwiches to students based on their preferences.\nKeep track of remaining sandwiches to be served.\nReturn the count of remaining sandwiches, representing the number of students unable to eat lunch.\n\n# Complexity Analysis:\nTime Complexity: O(n), where n is the number of students. We iterate through the students and sandwiches arrays once.\nSpace Complexity: O(1) in terms of auxiliary space as we use a constant amount of space to store counts.\n# Code\n``` java []\nclass Solution {\n    public int countStudents(int[] students, int[] sandwiches) {\n        int[] counts = new int[2];\n        for (int student : students) counts[student]++;\n        \n        int remaining = sandwiches.length;\n        for (int sandwich : sandwiches) {\n            if (counts[sandwich] == 0) break;\n            if (remaining-- == 0) break;\n            counts[sandwich]--;\n        }\n        \n        return remaining;\n    }\n}\n\n```\n``` C++ []\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n    int countStudents(vector<int>& students, vector<int>& sandwiches) {\n        vector<int> counts(2, 0);\n        for (int student : students)\n            counts[student]++;\n\n        int remaining = sandwiches.size();\n        for (int sandwich : sandwiches) {\n            if (counts[sandwich] == 0)\n                break;\n            if (remaining == 0)\n                break;\n            counts[sandwich]--;\n            remaining--;\n        }\n\n        return remaining;\n    }\n};\n```\n``` Python []\nclass Solution:\n    def countStudents(self, students: List[int], sandwiches: List[int]) -> int:\n        counts = [0, 0]\n        for student in students:\n            counts[student] += 1\n\n        remaining = len(sandwiches)\n        for sandwich in sandwiches:\n            if counts[sandwich] == 0:\n                break\n            if remaining == 0:\n                break\n            counts[sandwich] -= 1\n            remaining -= 1\n        \n        return remaining\n\n```\n![upvoteee.PNG](https://assets.leetcode.com/users/images/065dfe86-89aa-4c53-b43c-3d4e975b5f11_1712534720.174091.png)\n\n**\uD83D\uDC4D Upvote if you enjoyed the solution! \uD83D\uDC4D**\n
['Array', 'Stack', 'Queue', 'Simulation', 'Python', 'C++', 'Java', 'Python3']