Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Move zeros to the end

Hardware interview practice

Move zeros to the end

EasyArraysSystemVerilog

Move every non-zero element to the left in its original order and place all zeros at the end, in place.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
values = [0, 3, 0, 1, 2]
Expected output
[3, 1, 2, 0, 0]

Nonzero values keep their original order and every zero is moved to the suffix.

What to cover

Requirements

  1. Preserve non-zero order.
  2. Use no extra array.
  3. Write zeros into the vacated positions.
Continue practicing

Related questions

StringsClean palindrome check→Linked ListsRemove the nth node from the end→
asic.fyi · Learn silicon end to end.info@asic.fyi