# [2037\. Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/) :::spoiler Solution ```cpp= class Solution { public: int minMovesToSeat(vector<int>& seats, vector<int>& students) { sort(seats.begin(), seats.end()); sort(students.begin(), students.end()); int n = seats.size(); int moves = 0; for (int i = 0; i < n; ++i) { moves += abs(seats[i] - students[i]); } return moves; } }; ``` - T: $O(n \cdot \log n)$ - S: $O(1)$ :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up