Simple Approch || 4ms || Easy
Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to move students to seats such that the total number of moves is minimized.
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to move students to seats such that the total number of moves is minimized. Since moving a student to a closer seat will always require fewer moves than moving them to a farther seat, the best approach is to match each student with the nearest available seat.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nnlog(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\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 totalMoves = 0;\n        for (int i = 0; i < seats.size(); ++i) {\n            totalMoves += abs(seats[i] - students[i]);\n        }\n        return totalMoves;\n    }\n};\n```
['C++']