Implement iterators and write tests in Java
CoinbaseSoftware Engineer · OnsiteLast 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):
- Define a generic Iterator<T> interface with hasNext() and next().
- Implement ArrayIterator<T> over a fixed array.
- Implement PeekingIterator<T> that wraps any Iterator<T> and adds peek() without advancing.
- 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.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.