This content originally appeared on Level Up Coding - Medium and was authored by Leonard Yeo
Problem
Given an array of random positive numbers, move all the zeroes to the left of the array.
Conditions
- has to be done in place ( space-constrained, ie. cannot allocate a new array)
- the order of non-zero elements on the right do not matter
Example
Input : arr[] = {0, 1, 2, 5, 0, 3, 0, 3};
Output : arr[] = {0, 0, 0, 2, 1, 3, 3, 5};
Solution
Python
Golang
Takeaways
I hope this blog post helps someone struggling to understand on how to solve this problem. Stay tuned to the next post! Peace ✌️
Solve move all the zeroes to the left of the array was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Leonard Yeo
Leonard Yeo | Sciencx (2021-10-03T12:16:32+00:00) Solve move all the zeroes to the left of the array. Retrieved from https://www.scien.cx/2021/10/03/solve-move-all-the-zeroes-to-the-left-of-the-array/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.