Move Zeros to the End
Easy 20 XPArraysTwo Pointers
Commonly asked at Facebook, Microsoft, Zoho
Read a list of integers. Move all zeros to the end while keeping the order of the non-zero numbers, and print the result.
- Input
- One line of space-separated integers.
- Output
- The rearranged list, space-separated.
Sample 1
Input
0 1 0 3 12
Output
1 3 12 0 0
Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.The solution unlocks after 3 submissions.