Java O(n) Solution
\nclass Solution {\n    private int MAX_POS_NUM = 100;\n    \n    public int minMovesToSeat(int[] seats, int[] students) {\n        int[] seatsAtPos = getFreque
```\nclass Solution {\n    private int MAX_POS_NUM = 100;\n    \n    public int minMovesToSeat(int[] seats, int[] students) {\n        int[] seatsAtPos = getFrequencyArray(seats, MAX_POS_NUM);\n        int[] studentsAtPos = getFrequencyArray(students, MAX_POS_NUM);\n        \n        return iterateBothArraysAndAddMoves(seatsAtPos, studentsAtPos);\n    }\n    \n    private int[] getFrequencyArray(int[] nums, int maxNum) {\n        int[] freqArray = new int[maxNum + 1];\n        for (int i = 0; i < nums.length; ++i) {\n            ++freqArray[nums[i]];\n        }\n        return freqArray;\n    }\n    \n    private int iterateBothArraysAndAddMoves(int[] seatsAtPos, int[] studentsAtPos) {\n        int totalMoves = 0;\n        for (int i = 1, j = 1; i < seatsAtPos.length;) {\n            if (seatsAtPos[i] == 0) {\n                ++i;\n            } else if (studentsAtPos[j] == 0) {\n                ++j;\n            } else {\n                --seatsAtPos[i];\n                --studentsAtPos[j];\n                totalMoves += Math.abs(i - j);\n            }\n        }\n        \n        return totalMoves;\n    }\n}\n```
['Java']