Suppose we have an array which contains 2m elements. we can divide the array into two parts, the first one and the later one. My question is how to insert the later part of the array into the first part one by one, for example the array
{1,2,3,4,5,6,7,8,9,10}
after merge we have the new array
{1,6,2,7,3,8,4,9,5,10}
I know some method to to this such as use another buffer to store the temp data, but it is required that the space complexity should be O(1).
My question is whether there exist an optimized method with O(n) time complexity and O(1) space complexity?