SORTED-STACK ✅✅69_BEATS_100%✅✅🔥Easy Solution🔥With Explanation🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nwe need to seat the students in as little moves as possible \nfor that we need to know 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe need to seat the students in as little moves as possible \nfor that we need to know what is the nearest seat available for every student so that he can sit in the seat nearest to him which will save time and movement as much as possible lets see how we can find out that .\n# Approach\n<!-- Describe your approach to solving the problem. -->\nwe need to sort the seats and students in either asc or desc order your wish \nonce we have order in both we can simply find out the nearest seat to any student just by looking at the seat under the same index in seats array\nfrom there it is simple just calculate the moves ie difference btw seats[i] and students[i] and just return the total value\nthats it thank you \n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n![upvote.jpeg](https://assets.leetcode.com/users/images/8a686113-1283-4dbf-9576-743a8b8d2d42_1718250929.0042322.jpeg)\n\n# Code\n```javascript []\n/**\n * @param {number[]} seats\n * @param {number[]} students\n * @return {number}\n */\nvar minMovesToSeat = function(seats, students) {\n    seats.sort((a,b)=>b-a)\n    students.sort((a,b)=>b-a)\n    let len=seats.length\n    let res=0\n    for(let i=0;i<len;i++){\n        res+=(Math.abs(seats.pop()-students.pop()))\n    }\n    return res\n    \n};\n```\n```python []\nclass Solution:\n    def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:\n        seats.sort()\n        students.sort()\n        res = 0\n        for i in range(len(seats)):\n            res += abs(seats.pop() - students.pop())\n        return res\n\n```\n```java []\nimport java.util.Arrays;\n\npublic class MinMovesToSeat {\n    public int minMovesToSeat(int[] seats, int[] students) {\n        Arrays.sort(seats);\n        Arrays.sort(students);\n        int len = seats.length;\n        int res = 0;\n        for (int i = 0; i < len; i++) {\n            res += Math.abs(seats[len - 1 - i] - students[len - 1 - i]);\n        }\n        return res;\n    }\n}\n\n```\n```c []\n#include <stdio.h>\n#include <stdlib.h>\n\nint compare(const void *a, const void *b) {\n    return (*(int *)b - *(int *)a);\n}\n\nint minMovesToSeat(int seats[], int seatsSize, int students[], int studentsSize) {\n    qsort(seats, seatsSize, sizeof(int), compare);\n    qsort(students, studentsSize, sizeof(int), compare);\n    int res = 0;\n    for (int i = 0; i < seatsSize; i++) {\n        res += abs(seats[i] - students[i]);\n    }\n    return res;\n}\n\nint main() {\n    int seats[] = {3, 2, 1};\n    int students[] = {1, 2, 3};\n    int res = minMovesToSeat(seats, 3, students, 3);\n    printf("Minimum moves to seat: %d\\n", res);\n    return 0;\n}\n\n```
['C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']