Move Zeros

Given an array of integers, move all the 0s to the back of the array while maintaining the relative order of the non-zero elements. Do this in-place using constant auxiliary space.

Input:

1[1, 0, 2, 0, 0, 7]

Output:

1[1, 2, 7, 0, 0, 0]

Try it yourself

โ†
โ†‘TA ๐Ÿ‘จโ€๐Ÿซ