A faster way to simulate the process is that instead of moving the hole array, we can add some extra space in front of the array and simply move the element to the extra space. For example, in the sample input:
We can use a fenwick tree to simulate the process: mark a position with 1 if it’s occupied by some number and the prefix sum is how many elements is in front of it (i.e. the real position in the simulator). In the end, don’t forget to update the position of all the elements in case some are not moved.