MEDIUMasked at 2 companies

Zigzag Iterator

A medium-tier problem at 66% community acceptance, tagged with Array, Design, Queue. Reported in interviews at Coinbase and 1 others.

Founder's read

Zigzag Iterator is a medium-difficulty design problem that appears in assessments at Coinbase and Google. You're given two 1D arrays and need to build an iterator that alternates between them on each call to next(). It sounds simple until you hit the edge cases: what happens when one array is empty, when arrays have different lengths, or when you've exhausted one but not the other. The trick isn't the algorithm, it's the state management. If this hits your live OA and you blank on how to handle the alternation logic cleanly, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
2
Difficulty
MEDIUM
Acceptance
66%

Companies that ask "Zigzag Iterator"

If this hits your live OA

Zigzag Iterator is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The naive approach fails fast: just track which array you're on and alternate. But that breaks when one array is shorter. The real pattern is to separate concerns: maintain an index into each array and a flag for whose turn it is, then skip over exhausted arrays gracefully. Most candidates overthink the queue approach or get tangled in off-by-one errors when checking hasNext(). The core insight is that you're not building a complex data structure, you're writing a state machine that knows when to switch and when to stop. StealthCoder handles the edge cases where manual alternation leaves you stranded.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Zigzag Iterator recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Zigzag Iterator interview FAQ

Is Zigzag Iterator still asked at FAANG?+

Yes. Coinbase and Google both report it. It's a solid mid-level design interview signal because it separates candidates who can code from those who understand iterator patterns and state management. Don't expect it at every shop, but it's frequent enough to drill.

What's the actual trick to Zigzag Iterator?+

The trick is recognizing that hasNext() and next() need independent logic. hasNext() must handle the case where the current array is exhausted but the other isn't. Many candidates merge this into next() and break. Keep them separate and you're done.

How does this relate to the Iterator topic?+

Zigzag Iterator is a pure iterator design exercise. You're not using an existing iterator pattern, you're building one from scratch. It tests whether you understand the contract: hasNext() peeks, next() advances, and the two must stay in sync even under stress.

Do I really need Queue for this?+

No. Queue is overkill and a red herring. You need two index pointers and a toggle for whose turn it is. Some solutions queue up the arrays themselves, which wastes space. Stick to indices and flags.

What are the hard edge cases?+

Empty arrays, mismatched lengths, and calling hasNext() multiple times in a row without next(). The last one trips people because they don't realize hasNext() can't have side effects. Test with [1], [2, 3, 4] and you'll catch your bugs.

Want the actual problem statement? View "Zigzag Iterator" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.