Easyyy C++ || 3 Approaches || Sorting || PQ (Greedy) || Counting || All Beats 100%
1. Sorting \n\n\n# Complexity\n- Time complexity:O(n log n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity h
# 1. Sorting \n![image.png](https://assets.leetcode.com/users/images/32b331e9-0849-4ca0-b11f-e5cfe8d64aa9_1718249418.9087472.png)\n\n# Complexity\n- Time complexity:O(n log 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\n# Code\n```\nclass Solution {\npublic:\n    int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n        int n = seats.size();\n        int count = 0;\n\n        sort(seats.begin(), seats.end());\n        sort(students.begin(), students.end());\n\n        for (int i = 0; i < n; i++) {\n            count += abs(seats[i] - students[i]);\n        }\n\n        return count;\n    }\n};\n```\n\n# 2. Greedy using PQ\n![image.png](https://assets.leetcode.com/users/images/daae2ef3-b183-4102-bb2b-231b22ff1920_1718249478.4928658.png)\n\n# Complexity\n- Time complexity:O(n log n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n        int n = seats.size();\n        priority_queue<int> pq1, pq2;\n\n        for (int i = 0; i < n; i++) {\n            pq1.push(seats[i]);\n            pq2.push(students[i]);\n        }\n\n        int count = 0;\n\n        while (!pq1.empty()) {\n            int top1 = pq1.top();\n            int top2 = pq2.top();\n            count += abs(top2 - top1);\n            pq1.pop();\n            pq2.pop();\n        }\n\n        return count;\n    }\n};\n```\n# 3. Counting \n![image.png](https://assets.leetcode.com/users/images/5ad0d2e9-31e7-485f-99f7-f5bec986c4bc_1718250843.8054094.png)\n\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\n```\nclass Solution {\npublic:\n    int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n        int n = seats.size();\n        vector<int> count1(101);\n        vector<int> count2(101);\n\n        for (int i = 0; i < n; i++) {\n            count1[seats[i]]++;\n            count2[students[i]]++;\n        }\n\n        int i, j, count;\n        i = j = count = 0;\n\n        while (i <= 100 && j <= 100) {\n            while (i <= 100 && !count1[i])\n                i++;\n            while (j <= 100 && !count2[j])\n                j++;\n            if (i <= 100 && j <= 100) {\n                count1[i]--;\n                count2[j]--;\n                count += abs(i - j);\n            }\n        }\n\n        return count;\n    }\n};\n```
['Greedy', 'Sorting', 'Counting', 'Counting Sort', 'C++']