← 返回 jpmorgan 的题目列表Zero Compaction Array Coding
类型:qbank
After the code-review portion, the interviewer asked the original LeetCode Move Zeroes prompt. The candidate solved it quickly and used the remaining time for conversation, which reinforces that clarity and edge cases matter more than algorithmic depth in this slot.
Requirements
Given an array of integers, move all zero values to the end.
Preserve the relative order of the non-zero elements.
Perform the transformation in place if the interviewer asks for the standard version.
Use standard Move Zeroes semantics.
Notes
The usual clean implementation compacts non-zero values first, then fills the suffix with zeroes.
Preserve relative order; swapping every zero with a later non-zero can break stability if done carelessly.
This can appear after a code-review discussion in the same 45-minute Super Day round, so solve it concisely and narrate edge cases.
Preparation
Implement the in-place stable compaction version.
Test all zeroes, no zeroes, alternating zero/non-zero values, zeros at the beginning, and zeros at the end.