[C++] Linear time, counting sort
Let us exploit the last constraint 1 <= seats[i], students[j] <= 100 and trade some (constant) space in favor of O(n) time:\nc++\nint minMovesToSeat(vector<int>
Let us exploit the last constraint `1 <= seats[i], students[j] <= 100` and trade some (constant) space in favor of O(n) time:\n```c++\nint minMovesToSeat(vector<int>& seats, vector<int>& students) {\n\tint a[100] = {}, b[100] = {}, ans = 0;\n\tfor (int i : seats) ++a[i - 1];\n\tfor (int i : students) ++b[i - 1];\n\tfor (int i = 0, j = 0; i < 100;)\n\t\tif (!a[i]) ++i;\n\t\telse if (!b[j]) ++j;\n\t\telse {\n\t\t\tint diff = min(a[i], b[j]);\n\t\t\tans += diff * abs(i - j);\n\t\t\ta[i] -= diff;\n\t\t\tb[j] -= diff;\n\t\t}\n\treturn ans;\n}\n```
['C']