Katkat

Implement iterators and write tests in Java

CoinbaseSoftware Engineer · Onsite

Last updated

Implement iterators and write tests in Java evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

In Java, write everything from scratch (no IDE scaffolding):

  1. Define a generic Iterator<T> interface with hasNext() and next().
  2. Implement ArrayIterator<T> over a fixed array.
  3. Implement PeekingIterator<T> that wraps any Iterator<T> and adds peek() without advancing.
  4. Provide minimal unit tests that compile and run, covering empty input, single element, multiple elements, and calling next() when no elements remain. Analyze time/space complexity and edge cases.