Simple 0ms C++/Python3 Solution With Greedy
Intuition\nAt first look the problem you have understand this problem what is the problem trying to say but it can be a little hard for this problem because thi
# Intuition\nAt first look the problem you have understand this problem what is the problem trying to say but it can be a little hard for this problem because this problem is not written well but after you understand what it is trying to tell you will have a intuition about can we solve this problem using greedy technuquie and lokks like you are right so let\'s look at the our approach\n\n# Approach\n\n1. We will use greedy aproach to this problem and for make greedy firstly we have to sort our arrays \n\n1. After the sortment we iterate thorught array values and we subtract them and get absolute value of this \n\n1. Reason of do all this process if we sort arrays and we get first values we choose the smallest value of both arrays \n\n1. If we subtract them we get min difference \n\n1. As you predict we have to get absolute value of them because distance cannot be negative \n1. when the array finished we found our result and return it\n\n# Complexity\n- Time complexity: $$O(n \\log n)$$\n\n- Space complexity: $$O(1)$$\n\n```python3 []\nclass Solution:\n    def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:\n        seats.sort()\n        students.sort()\n        result = 0\n        for i in range(len(seats)):\n            result += abs(seats[i] - students[i])\n        return result\n```\n```C++ []\nclass Solution {\npublic:\n    int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n        int result = 0;\n        sort(seats.begin(),seats.end());\n        sort(students.begin(),students.end());\n        for(int i = 0;i < seats.size(); i++){\n            result += abs(students[i] - seats[i]);\n        }\n        return result;\n    }\n};\n```\n
['Array', 'Greedy', 'Sorting', 'C++', 'Python3']