Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Move all zeros to the end of an array, keeping the order of other elements.

Medium

Problem Statement

Move all zeros to the end of an array, keeping the order of other elements.

Sample Input

[0, 1, 0, 3, 12]

Sample Output

[1, 3, 12, 0, 0]

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import java.util.*; public class Main { public static int[] moveZeros() { int[] arr = {0, 1, 0, 3, 12}; // Your code here return arr; } }
Log in or sign up to run or submit your code.Log inSign up
Input
[0, 1, 0, 3, 12]
Expected Output
[1, 3, 12, 0, 0]