Java Solution, Beats 100%
Intuition:\nThe core idea of the solution is to use a frequency array to track the imbalance between the number of students and the number of seats at each posi
# Intuition:\nThe core idea of the solution is to use a frequency array to track the imbalance between the number of students and the number of seats at each position. By iterating through this frequency array, we can determine the minimum number of moves required to balance this imbalance, effectively assigning each student to a seat.\n\n# Approach:\n\n1. **Initialization**:\n   - Create an array `pos` of size 101 (since the positions range from 1 to 100).\n   - Initialize a variable `res` to store the result (the total number of moves).\n   - Initialize a variable `current` to keep track of the current imbalance.\n\n2. **Populate the `pos` array**:\n   - For each position in the `seats` array, increment the corresponding index in the `pos` array.\n   - For each position in the `students` array, decrement the corresponding index in the `pos` array.\n   - This will help in tracking the net effect of students and seats at each position.\n\n3. **Calculate the minimum moves**:\n   - Iterate through the `pos` array.\n   - For each element in `pos`, add the absolute value of `current` to `res`.\n   - Update `current` by adding the current element of `pos` to it.\n   - This step effectively accumulates the total number of moves required to balance the students and seats.\n\n# Complexity:\n\n## Time Complexity:\n- **Initialization and population of `pos` array**: \n  - Iterating through the `seats` array and the `students` array: O(n)\n- **Calculating the minimum moves**:\n  - Iterating through the `pos` array (fixed size of 101): O(1)\n\nThus, the overall time complexity is **O(n)**.\n\n## Space Complexity:\n- The `pos` array is of fixed size 101, which is a constant space: O(1)\n- Additional variables (`res` and `current`): O(1)\n\nThus, the overall space complexity is **O(1)**.\n\n# Code:\n\n```java\nclass Solution {\n    public int minMovesToSeat(int[] seats, int[] students) {\n        int[] pos = new int[101];  // Frequency array for positions (1 to 100)\n        int n = seats.length;\n        \n        // Populate the frequency array based on seats and students positions\n        for (int i = 0; i < n; i++) {\n            pos[seats[i]]++;  // Increment for each seat position\n            pos[students[i]]--;  // Decrement for each student position\n        }\n        \n        int res = 0;  // Result to store the minimum number of moves\n        int current = 0;  // Current imbalance of students and seats\n        \n        // Calculate the total moves required\n        for (int i : pos) {\n            res += Math.abs(current);  // Add the absolute value of the current imbalance\n            current += i;  // Update the current imbalance\n        }\n        \n        return res;  // Return the total number of moves\n    }\n}\n```
['Java']