← Coinbase Interview Insights

Coinbase·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Coinbase software engineering interview that was basically a deep dive into iterator design in Java, all written from scratch with no IDE help. The scope was bigger than I expected, covering generics, wrapper patterns, unit tests, and complexity analysis in one shot.

Questions Asked (1)

Q1

In Java, define a generic Iterator interface with hasNext() and next(), implement an ArrayIterator over a fixed array, then wrap it with a PeekingIterator that adds peek() without advancing the cursor. Write minimal unit tests covering empty input, single element, multiple elements, and calling next() past the end. Analyze time and space complexity for each component.

Algorithms & Data StructuresTechnical Trade-offsAPI & Integrations
Author's notes

This felt like four questions crammed into one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining a generic Iterator<T> interface with hasNext() and next(), then implement ArrayIterator<T> over a fixed array with an index. Wrap it with PeekingIterator<T> that caches the next element for peek() without advancing the underlying iterator. Write minimal unit tests for edge cases and analyze time/space complexity for each component.

Pro tip: Mention that PeekingIterator should handle NoSuchElementException consistently and that peek() should not advance the underlying iterator. Also, note that the wrapper pattern allows adding functionality without modifying the original iterator.

1. Define the Iterator interface

Create a generic Iterator<T> interface with methods boolean hasNext() and T next(). Specify that next() throws NoSuchElementException when no more elements.

2. Implement ArrayIterator

Implement ArrayIterator<T> that takes a fixed array in the constructor, maintains an index, and implements hasNext() and next() accordingly.

3. Implement PeekingIterator

Implement PeekingIterator<T> that wraps an Iterator<T>, caches the next element for peek(), and ensures peek() does not advance the underlying iterator.

4. Write unit tests

Write minimal unit tests covering empty input, single element, multiple elements, and calling next() past the end (expecting NoSuchElementException).

5. Analyze complexity

Analyze time and space complexity for each component: ArrayIterator has O(1) time for hasNext and next, O(1) space; PeekingIterator has O(1) time for peek, hasNext, next, and O(1) extra space.

Key Points to Mention

  • Generic type parameter <T> for type safety and reusability.
  • Proper exception handling: next() throws NoSuchElementException when exhausted.
  • PeekingIterator uses a cache (e.g., a boolean flag and a variable) to store the next element for peek().
  • Unit tests should cover edge cases: empty iterator, single element, multiple elements, and calling next() past the end.
  • Time complexity: O(1) for all operations in both iterators.
  • Space complexity: O(1) for ArrayIterator (excluding input array), O(1) extra for PeekingIterator.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.