All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 02, 2024
Last updated : July 01, 2024
Related Topics : Array, Stack, Queue, Simulation
Acceptance Rate : 78.48 %
class Solution:
def countStudents(self, students: List[int], sandwiches: List[int]) -> int:
cycleCounter = 0
currStudent = 0
while cycleCounter < len(students) :
if students[currStudent] == sandwiches[0]:
sandwiches.pop(0)
students.pop(currStudent)
cycleCounter = 0
else :
currStudent += 1
cycleCounter += 1
if len(sandwiches) == 0 or len(students) == 0 :
break
currStudent %= len(students)
return len(students)
class Solution:
def countStudents(self, students: List[int], sandwiches: List[int]) -> int:
squareStudents = sum(students)
currStudent = 0
while True:
if sandwiches[0] :
if not squareStudents :
break
elif students[currStudent] :
students.pop(currStudent)
sandwiches.pop(0)
squareStudents -= 1
else :
currStudent += 1
else :
if not (len(students) - squareStudents) :
break
elif not students[currStudent] :
students.pop(currStudent)
sandwiches.pop(0)
else :
currStudent += 1
if len(students) == 0 :
break
currStudent %= len(students)
return len(students)