Array Manipulations

Problem Description
Given a dynamic array of integers, move all non-zero elements to the left while maintaining their relative order. All zero elements should be moved to the right.
Rules:
Move all non-zero elements to the left while keeping their order.
Push all zeros to the right (in-place, no extra arrays).
Examples
Example 1
Input Array:
arr[] = '{1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0}Expected Output:
arr[] = '{1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0}
Example 2
Input Array:
arr[] = '{0, 0, 0, 1, 2, 3}Expected Output:
arr[] = '{1, 2, 3, 0, 0, 0}
Example 3
Input Array:
arr[] = '{5}Expected Output:
arr[] = '{5}
SystemVerilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
Output
Output goes here...
