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.