PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Coinbase

Implement custom iterators and interfaces

Last updated: Mar 29, 2026

Quick Overview

This question evaluates implementation and API-design skills for iterators, specifically interface design and iterator semantics (hasNext/next), edge-case handling, correct exception behavior, amortized time and space complexity, and unit-testable behavior when implementing FlattenIterator and FilterIterator over integer collections in Java.

  • Medium
  • Coinbase
  • Coding & Algorithms
  • Software Engineer

Implement custom iterators and interfaces

Company: Coinbase

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Define a minimal Iterator interface (e.g., hasNext(), next()) for integers without using IDE-generated scaffolding. Implement two iterator classes in Java: ( 1) FlattenIterator that iterates through a list of lists of integers, skipping empty lists; ( 2) FilterIterator that wraps any Integer iterator and yields only elements satisfying a provided predicate. Both must be robust to edge cases (empty input, single element, repeated hasNext() calls), throw appropriate exceptions when next() is invalid, and operate in O( 1) amortized time per element with O( 1) or O(depth) extra space as appropriate. Provide brief unit tests demonstrating correctness and discuss time/space complexity.

Quick Answer: This question evaluates implementation and API-design skills for iterators, specifically interface design and iterator semantics (hasNext/next), edge-case handling, correct exception behavior, amortized time and space complexity, and unit-testable behavior when implementing FlattenIterator and FilterIterator over integer collections in Java.

Related Interview Questions

  • Implement an In-Memory Database - Coinbase (hard)
  • Implement a Coin-Constrained Jump Strategy - Coinbase (hard)
  • Implement Game Physics and Block Mining - Coinbase (hard)
  • Compute Total Manual Distance - Coinbase (medium)
  • Implement a Flappy Bird Jump Agent - Coinbase
Coinbase logo
Coinbase
Jul 31, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
5
0

Define a minimal Iterator interface (e.g., hasNext(), next()) for integers without using IDE-generated scaffolding. Implement two iterator classes in Java: (

  1. FlattenIterator that iterates through a list of lists of integers, skipping empty lists; (
  2. FilterIterator that wraps any Integer iterator and yields only elements satisfying a provided predicate. Both must be robust to edge cases (empty input, single element, repeated hasNext() calls), throw appropriate exceptions when next() is invalid, and operate in O(
  3. amortized time per element with O(
  4. or O(depth) extra space as appropriate. Provide brief unit tests demonstrating correctness and discuss time/space complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Coinbase•More Software Engineer•Coinbase Software Engineer•Coinbase Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.