# [LeetCode]#2037. Minimum Number of Moves to Seat Everyone

• Increase or decrease the position of the `ith` student by `1` (i.e., moving the `ith` student from position `x` to `x + 1` or `x - 1`)
`Input: seats = [3,1,5], students = [2,7,4]Output: 4Explanation: The students are moved as follows:- The first student is moved from from position 2 to position 1 using 1 move.- The second student is moved from from position 7 to position 5 using 2 moves.- The third student is moved from from position 4 to position 3 using 1 move.In total, 1 + 2 + 1 = 4 moves were used.`
1. Sort seats and students.
2. Use for loop.
3. Get difference abs(seats[i]-students[i]) and sum them.
`class Solution:    def minMovesToSeat(self, seats, students):        ans=0        seats.sort()        students.sort()        for i in range(len(seats)):            ans=ans+abs(seats[i]-students[i])        return ans`

--

--

--

## More from Fatboy Slim

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

## Fatboy Slim

Interesting in any computer science.