Move all zeroes to end of array

Given an array of integer elements, Our goal is to move existing zero to last (end) of given array. For example.

Example
Input 
arr1[] = { 0, 1, 4, 7, 2, 2, 1, 2, 0, 0, 6, 0, 1, 1, 0 }

Output
arr1[] = { 1, 1, 4, 7, 2, 2, 1, 2, 1, 6, 0, 0, 0, 0, 0 }
                                         |<---------->|

Note that this is modifying the actual array. Write a better algorithm which are taking O(n) time And not use any extra space.

Here mentioned few solution which is suitable in above scenario.




Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2022, kalkicode.com, All rights reserved