Skip to content
LC-1700 Easy LeetCode

1700. Number of Students Unable to Eat Lunch

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 79% Topics: Array, Stack, Queue, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

import collections


class Solution(object):
    def countStudents(self, students, sandwiches):
        """
        :type students: List[int]
        :type sandwiches: List[int]
        :rtype: int
        """
        count = collections.Counter(students)
        for i, s in enumerate(sandwiches):
            if not count[s]:
                break
            count[s] -= 1
        else:
            i = len(sandwiches)
        return len(sandwiches)-i

Solution from kamyu104/LeetCode-Solutions · MIT