DEV Community

Saranya R
Saranya R

Posted on

Move Zeroes

Approach Explanation o(〃^▽^〃)o

  1. I used a pointer ptr to track where the next non‑zero should be placed.
  2. I scanned the array from left to right.
  3. Whenever I found a non‑zero, copied it to the position at ptr and moved ptr forward.
  4. After placing all non‑zeros, I filled the remaining positions with zeroes.
  5. This way, all non‑zeros stayed in their original order, and all zeroes were pushed to the end

Method Used: (〜 ̄▽ ̄)〜

  • Two‑phase approach
  • Pointer tracking
  • In‑place modification
  • Stable order
  • Efficient traversal

Top comments (0)