Implement Composable Range Iterators

Quick Overview

This question evaluates understanding of iterator design, lazy evaluation, composable higher-order combinators (map, filter, zip, take, drop, chain), edge-case handling for forward/backward and negative-step ranges, overflow-safe termination, peekable semantics, iterator invalidation rules, and writing boundary-focused unit tests.

Implement Composable Range Iterators

Company: Coinbase

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement an iterator library: range(start, end, step= 1) supporting forward/backward iteration, inclusive/exclusive endpoints, negative steps, and overflow-safe termination. Provide lazy combinators map, filter, zip, take(n), drop(n), and chain, each with O( 1) extra space and amortized O( 1) per element. Add a PeekableIterator with peek() and hasNext(); discuss whether and how reset()/rewind() can be supported without materializing the sequence. Define iterator invalidation rules when the underlying collection changes. Write unit tests for boundary cases (very large ranges, zero step, empty ranges, negative steps) and demonstrate usage in your preferred language.

Quick Answer: This question evaluates understanding of iterator design, lazy evaluation, composable higher-order combinators (map, filter, zip, take, drop, chain), edge-case handling for forward/backward and negative-step ranges, overflow-safe termination, peekable semantics, iterator invalidation rules, and writing boundary-focused unit tests.

|Home/Coding & Algorithms/Coinbase
Coinbase logo
Coinbase
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
13
0

Implement an iterator library: range(start, end, step=

  1. supporting forward/backward iteration, inclusive/exclusive endpoints, negative steps, and overflow-safe termination. Provide lazy combinators map, filter, zip, take(n), drop(n), and chain, each with O(
  2. extra space and amortized O(
  3. per element. Add a PeekableIterator with peek() and hasNext(); discuss whether and how reset()/rewind() can be supported without materializing the sequence. Define iterator invalidation rules when the underlying collection changes. Write unit tests for boundary cases (very large ranges, zero step, empty ranges, negative steps) and demonstrate usage in your preferred language.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...