Skip to content

Latest commit

 

History

History
82 lines (64 loc) · 2.31 KB

_1700. Number of Students Unable to Eat Lunch.md

File metadata and controls

82 lines (64 loc) · 2.31 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 02, 2024

Last updated : July 01, 2024


Related Topics : Array, Stack, Queue, Simulation

Acceptance Rate : 78.48 %


Solutions

Python

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)