Move Zeroes to End
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
LEARN BY DOINGPut your intuition to work3 steps
Move Zeroes to End
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.1 3 12 0 0
Sample case — your program reads stdin and prints to stdout.
Starter Given an array of integers, move all zeroes to the end while maintaining the relative order of non-zero elements.
Use two pointers: one for the position to insert non-zero, one to scan.
Example: [0,1,0,3,12] → [1,3,12,0,0]
Input format
Line 1: n. Line 2: n space-separated integers.
Output format
The array with zeroes moved to end, space-separated.
Constraints
1 ≤ n ≤ 10⁴