β Move Zeros(Contest)
Move Zeros easy asked in interviews by 8 companies Time Limit: 2 sec Memory Limit: 128000 kB
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int arr[] = new int[n];
for(int i = 0; i < n; i++){
arr[i] = sc.nextInt();
}
int j = 0;
int zerocCount = 0;
for(int i = 0; i <n; i++){
if(arr[i] == 0){
zerocCount++;
} else{
arr[j] = arr[i];
j++;
}
}
while(j < n){
arr[j] = 0;
j++;
}
for(int i = 0; i < n; i++){
System.out.print(arr[i]+ " ");
}
System.out.println();
}
}
}
```Last updated