Close
Topic list
Move Zeroes To End
MEDIUM
30 mins
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Arrays
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Move Zeroes To End

Contributed by
Anup Kumar Singh
Medium
0/80
Avg time to solve 30 mins
Success Rate 70 %
Share

## Problem Statement

#### Expected Complexity: Try doing it in O(n) time complexity and O(1) space complexity. Here, ‘n’ is the size of the array.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````2
7
2 0 4 1 3 0 28
5
0 0 0 0 1
``````
##### Sample Output 1:
``````2 4 1 3 28 0 0
1 0 0 0 0
``````
##### The explanation for Sample Output 1 :
``````In the first testcase, All the zeros are moved towards the end of the array, and the non-zero elements are pushed towards the left, maintaining their order with respect to the original array.

In the second testcase, All zero are moved towards the end, hence the only non-zero element i.e 1 is in the starting of the array
``````
##### Sample Input 2:
``````2
5
0 3 0 2 0
4
0 0 0 0
``````
##### Sample Output 2:
``````3 2 0 0 0
0 0 0 0
``````
Auto
Console