Skip to content

Practice Minimum Number of Moves to Seat Everyone

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2037
LeetCode Problem

Minimum Number of Moves to Seat Everyone

Problem Statement

There are equally many seats and students, with positions given by seats and students. A move changes one student’s position by 1 in either direction. Assign every student to a different seat and return the minimum total moves needed. Distinct seats may share a position, and multiple students may initially share a position.

Source: Minimum Number of Moves to Seat Everyone on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
seats = [3,1,5], students = [2,7,4]
Output
4

# Example 2

Input
seats = [4,1,5,9], students = [1,3,2,6]
Output
7

# Example 3

Input
seats = [2,2,6,6], students = [1,3,2,6]
Output
4

Constraints

n == seats.length == students.length
1 <= n <= 100
1 <= seats[i], students[j] <= 100

Related LeetCode Problems

Practice more problems similar to Minimum Number of Moves to Seat Everyone.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.