Simple C++ Solution Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to find the minimum distance between the student and the target seat. So sortin
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to find the minimum distance between the student and the target seat. So sorting helps by ordering the students and the seats.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSort both the students and the seats. Now just add up the absolute difference between all of them, the sum is the required answer. This results in the correct answer because if you don\'t take the i\'th seat for the i\'th student, you are essentially incresing the total sum as the array is sorted and you cannot find another element that will have smaller difference.\n# Complexity\n- Time complexity:O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n        sort(seats.begin(),seats.end());\n        sort(students.begin(),students.end());\n        int res = 0;\n        for(int i=0; i<seats.size(); i++){\n            res += abs(students[i] - seats[i]);\n        }\n        return res;\n    }\n};\n```\n\n# Please upvote if the solution helped you!
['C++']