Move Zeroes

Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.

Topic refresher: Arrays — Index Thinking

Treat every array problem as: What do I know at index i? What must I remember from the past?

// Running best pattern
int best = nums[0];
for (int i = 1; i < n; i++) {
    // update state using nums[i]
    best = max(best, candidate);
}
return best;
Arrays

Move Zeroes

Easy
LeetCode
5/14
EasyArraysLeetCode #283

Move Zeroes in-place

Two pointers: write non-zeros forward, then fill the rest with zeros.

Examples

Example 1

Input

5
0 1 0 3 12

Output

1 3 12 0 0
Example 2

Input

1
0

Output

0

Stuck? Take a nudge

C++17