Given an array of integers, write a code to move all zeroes to end of array. The order of all other elements of an array should be same.
Now, In this question we have to write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
NOTE : We have to solve this problem in–place without making a copy of the array.
For example –
Example 1:
Input : {1, 2, 0, 4, 0, 5, 3, 8}
Output: {1, 2, 4, 5, 3, 8, 0, 0}
In this example, All zeros are moved to the end of array and the relative order of non-zero elements is also maintained.
Example 2:
Input : {1, 0, 2, 3, 0, 0, 0, 2}
Output : {1, 2, 3, 2, 0, 0, 0, 0}