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…
More Goldman Sachs interview questions
- Merge K Sorted Lists (including K=3)
- Goldman Hirevue Behavioral Bank (6 Questions)
- Goldman Sachs HireVue Behavioral and Recursion
- Probability and Statistics Drill: Eight Numeric Problems
- Explain Recursion to a Non-CS Audience
- Implement a Deque From Scratch