Skip to content
LC-2037 Easy LeetCode

2037. Minimum Number of Moves to Seat Everyone

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 87% Topics: Array, Greedy, Sorting, Counting Sort
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogn)
# Space: O(1)

import itertools


class Solution(object):
    def minMovesToSeat(self, seats, students):
        """
        :type seats: List[int]
        :type students: List[int]
        :rtype: int
        """
        seats.sort()
        students.sort()
        return sum(abs(a-b) for a, b in itertools.izip(seats, students))

Solution from kamyu104/LeetCode-Solutions · MIT