Zigzag Iterator for Two 1D Vectors

Asked at Goldman Sachs · Coding & Leetcode-style Questions · Difficulty: Medium

Given two 1D vectors v1 and v2, implement an iterator class ZigzagIterator to return elements from these two vectors alternately. The next() method should return the next element, and hasNext() should return true if there are more elements and false otherwise. You should iterate from both vectors alternately, taking elements one at a time, until all elements are used. If one vector is finished, just continue taking elements from the other vector.

Loading the problem…