Simple and easy solution in Java!! with Dry run table ✅✅✅
Approach\n Describe your approach to solving the problem. \n1. Sort Both Arrays: Sort the seats and students arrays. This ensures that the smallest difference i
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. **Sort Both Arrays**: Sort the `seats` and `students` arrays. This ensures that the smallest difference is obtained when each student is assigned to the closest seat in sorted order.\n2. **Calculate Moves**: Iterate through both arrays and compute the required moves as the sum of the absolute differences between the corresponding elements in the `seats` and `students` arrays.\n\n# Dry Run Example\n\n### Example\n`seats = [3, 1, 5]`, `students = [2, 7, 4]`\n\n1. **Sort Both Arrays**:\n    - `seats = [1, 3, 5]`\n    - `students = [2, 4, 7]`\n\n2. **Calculate Moves**:\n\n| Index | Seats | Students | Required Moves         | Total Moves |\n|-------|------|---------|---------------|-------------|\n| 0     | 1    | 2       | \\|1 - 2\\| = 1 | 1           |\n| 1     | 3    | 4       | \\|3 - 4\\| = 1 | 2           |\n| 2     | 5    | 7       | \\|5 - 7\\| = 2 | 4           |\n\n**Total Moves**: `4`\n\n# Steps with Code\n\n1. **Sort the Arrays**:\n    ```java\n    Arrays.sort(seats);\n    Arrays.sort(students);\n    ```\n    - Sorting both arrays to ensure the minimum total moves.\n\n2. **Calculate the Total Moves**:\n    ```java\n    int requiredSeats = 0;\n    for (int i = 0; i < seats.length; i++) {\n        requiredSeats += Math.abs(seats[i] - students[i]);\n    }\n    ```\n    - Iterating through the sorted arrays and calculating the total moves.\n\n3. **Return the Result**:\n    ```java\n    return requiredSeats;\n    ```\n    - Returning the total number of moves.\n# Complexity\n\n**Time Complexity**: O(n log n)\n\n- Sorting both seats and students arrays takes O(n log n) time.\n- Iterating through the arrays takes O(n) time.\n- Overall, the time complexity is O(n log n).\n\n**Space Complexity**: O(1)\nThe space complexity is constant as we are using a fixed amount of extra space regardless of the input size.\n\n# Code\n```\nclass Solution {\n    public int minMovesToSeat(int[] seats, int[] students) {\n        Arrays.sort(seats);\n        Arrays.sort(students);\n\n        int requiedSeats = 0;\n\n        for(int i = 0; i < seats.length; i++)\n        {\n            requiedSeats += Math.abs(seats[i] - students[i]);\n        }\n\n        return requiedSeats;\n    }\n}\n```\n\n![image.png](https://assets.leetcode.com/users/images/1b2a6ae8-7dc5-4957-b245-2547e06627b2_1718256012.855786.png)\n
['Java']