Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ847
Page ↗
Q847FWASIC interview problem

Move zeros to the end

TechniquesArrayTwo pointersStable
DifficultyEasy
TopicArrays
LanguageSystemVerilog
Requirements3 checkpoints
01

Problem

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

Example input and output

Use this case to check your interpretation
Input
values = [0, 3, 0, 1, 2]
Output
[3, 1, 2, 0, 0]
Explanation

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

02

Requirements (3)

  • Preserve non-zero order.
  • Use no extra array.
  • Write zeros into the vacated positions.