JAVA Solution Explained in HINDI(2 Approaches)
https://youtu.be/LMtzSS7r3HU\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote 
https://youtu.be/LMtzSS7r3HU\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\nSubscribe Goal:- 500\nCurrent Subscriber:- 432\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n+m+k)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(m+k)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minMovesToSeat(int[] seats, int[] students) {\n        int maxSeat = Arrays.stream(seats).max().getAsInt();\n        int maxStudent = Arrays.stream(students).max().getAsInt();\n        \n        int[] seatLoc = new int[maxSeat + 1];\n        int[] studentsFreq = new int[maxStudent + 1];\n\n        for (int loc : seats) {\n            seatLoc[loc]++;\n        }\n        for (int student : students) {\n            studentsFreq[student]++;\n        }\n\n        int ans = 0, j = 0;\n        for (int i = 0; i < seatLoc.length; i++) {\n            if (seatLoc[i] == 0) continue;\n            while (studentsFreq[j] == 0) j++;\n            ans += Math.abs(i - j);\n            studentsFreq[j]--;\n            seatLoc[i]--;\n            if (seatLoc[i] != 0) i--;\n        }\n\n        return ans;\n    }\n}\n```\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(logn)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n```\nclass Solution {\n    public int minMovesToSeat(int[] seats, int[] students) {\n        Arrays.sort(seats);\n        Arrays.sort(students);\n\n        int ans = 0;\n        for (int i = 0; i < seats.length; i++) {\n            ans += Math.abs(seats[i] - students[i]);\n        }\n\n        return ans;\n    }\n}\n```
['Java']