Minimum Number of Moves to Seat Everyone Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nAs we have to minimize the moves, the students and the seats have to be paired upon suc
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs we have to minimize the moves, the students and the seats have to be paired upon such a way that each pairing takes less no of moves. To form such pairs, the sort method would be optimal and helpful.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort seats and students array.\n2. Length of the array - calculated through len method - for traversing.\n3. Traverse through both the arrays simultaneously. \n- If both the values are same that means the student does not have to move.\n- Otherwise student has to move either side, whose value is calculated and taken absolute value, which is being added to counter variable moves.\n4. At the end, the counter variable moves, is being returned.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of the above approach used is O(NLogN) {reduced due to sorting the arrays}\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nAs only one counter variable is used for storing the moves thus space complexity is of only O(1).\n\n# Code\n```\nimport math\nclass Solution:\n    def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:\n        moves=0\n        seats.sort()\n        students.sort()\n        for i in range(len(seats)):\n            if(students[i]!=seats[i]):\n                moves = moves + abs(students[i]-seats[i])        \n        return moves\n        \n```
['Python3']