Python Easy Stack Solution
Focus on the while condition the loop inside is just what the condition says. The len(sandwiches)==len(students) this is given to us. If the students get what t
# Focus on the while condition the loop inside is just what the condition says. The len(sandwiches)==len(students) this is given to us. If the students get what they want then both the list will get empty eventually and we can break the loop to get the length of the list which will be zero. For example consider this sandwiches : [1,0,1] and students : [0,1,1] we can always pop students from the start and append them to the end if they dont get the sandwich they want, eventually we will have this [0,1] and [0,1] and then they will all leave, now we need to check the situation when no matter how many times we rotate the students they wont get what they want, that would be the condition which will keep our loop going, to break out of the condition, notice this. That situation will happen only if the top of the sandwich stack option is wanted by none of the remaining students at any moment that would be the condition in which no matter how many times we rotate the students they wont get the sandwhich ever, this will keep on going, This will happen if top of sandwhich is \'0\' and we have student array like [1,1,1,1,1,1,1] or the opposite. To break out of this condition I have put if sandwhich[0] in students as one of the while condiiton as well to break out of the situation, in the end we just need to return the length of the students left.\n\n\n# Upvote if you found the intuition helpful and found the explanation easy to understand. Thanks\n\n```\nclass Solution:\n    def countStudents(self, students: List[int], sandwiches: List[int]) -> int:\n        \n        while students and sandwiches and sandwiches[0] in students:\n                if students[0]==sandwiches[0]:\n                    students.pop(0)\n                    sandwiches.pop(0)\n                else:\n                    k = students.pop(0)\n                    students.append(k)\n                \n        print(students)\n        return len(students)\n```
['Stack', 'Python']