Move all zeros present in an array to the end


Asked In: YahooAmazon

Given an array of integers, move all zeros present in the array to the end. The solution should maintain the relative order of items in the array.

Example:

Example:
Input : [1,3,0,0,4,0,9]

Modify array so that it becomes :[1 3 4 9 0 0 0] 

Constraint1 : You are not suppose to use any
extra space
Constraint2 : You need to change the same array
with single traversal with O(n) time complexity

Problem level: Easy