Solution in JAVA || Beginner friendly || with easy explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Firstly sort both array (i.e. seats, students)\n2. Create \'moves\' va
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Firstly sort both array (i.e. seats, students)\n2. Create \'moves\' variable of type int.\n3. Iterate both array using for loop.\n4. subtract values for every index of \'seats\' and \'students\' and add subtraction to \'moves\' variable.\n5. return moves;\n\n# Complexity\n- Time complexity: O(n log n)\n\n- Space complexity: O(1)\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 moves = 0;\n        for(int i=0; i<students.length; i++){\n            moves = moves + Math.abs(seats[i]-students[i]);\n        }\n\n        return moves;\n    }\n}\n```
['Java']