PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Airbnb

Implement a Removable Nested-List Iterator

Last updated: Jul 28, 2026

Quick Overview

Implement an iterator over mutable nested integer lists with repeatable lookahead and a legal once-per-item removal operation. Preserve traversal order through empty rows and deletions, expose mutations in the original input, and define exhaustion and illegal-state behavior precisely.

  • easy
  • Airbnb
  • Coding & Algorithms
  • Software Engineer

Implement a Removable Nested-List Iterator

Company: Airbnb

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Implement a Removable Nested-List Iterator Implement an iterator over a mutable array of integer arrays. Traversal goes left to right within each inner array and top to bottom across the outer array. Empty inner arrays are skipped. Your class must expose: ```text hasNext() -> bool next() -> int remove() -> void ``` `remove()` deletes from the original nested-list object the element returned by the most recent successful `next()`. ### Required Behavior - `hasNext()` reports whether another integer remains and may be called repeatedly without advancing the iterator. - `next()` returns the next integer. It raises an iteration-exhausted exception when no value remains. - `remove()` is legal exactly once after each successful `next()`. - Calling `remove()` before `next()`, or calling it twice after the same `next()`, raises an illegal-state exception. - Removing an element must not cause the following element in the same row to be skipped. - Mutations made by `remove()` must be visible through the original nested list supplied to the constructor. ### Example ```text data = [[], [1, 2, 3], [4, 5], [], [6]] it = NestedIterator(data) it.hasNext() -> true it.next() -> 1 it.next() -> 2 it.remove() data -> [[], [1, 3], [4, 5], [], [6]] it.next() -> 3 ``` ### Constraints - The outer and inner arrays exist for the lifetime of the iterator. - Clients do not mutate the nested arrays except through this iterator's `remove()`. - Values may repeat; position, not value, identifies what must be removed. - Empty outer input is valid. ### Hints - Maintain a row and column for the next candidate, plus the exact position last returned. - Centralize skipping of empty or exhausted rows in one helper. - Deleting from the same row shifts later columns left; adjust the cursor accordingly. ### Discussion Extensions - Give the amortized cost of traversal and the cost of removal for array-backed rows. - How would fail-fast behavior work if external mutation had to be detected? - What changes if inner collections are linked lists rather than arrays?

Quick Answer: Implement an iterator over mutable nested integer lists with repeatable lookahead and a legal once-per-item removal operation. Preserve traversal order through empty rows and deletions, expose mutations in the original input, and define exhaustion and illegal-state behavior precisely.

Related Interview Questions

  • Minimum Canisters to Top Up an Exact Target - Airbnb (medium)
  • Count Candies from Unlockable Boxes - Airbnb (medium)
  • Find Optimal Property Combination - Airbnb (medium)
  • Flatten a Nested Integer List - Airbnb (hard)
|Home/Coding & Algorithms/Airbnb

Implement a Removable Nested-List Iterator

Airbnb logo
Airbnb
Jul 14, 2026, 12:00 AM
easySoftware EngineerTechnical ScreenCoding & Algorithms
6
0

Implement a Removable Nested-List Iterator

Implement an iterator over a mutable array of integer arrays. Traversal goes left to right within each inner array and top to bottom across the outer array. Empty inner arrays are skipped.

Your class must expose:

hasNext() -> bool
next() -> int
remove() -> void

remove() deletes from the original nested-list object the element returned by the most recent successful next().

Required Behavior

  • hasNext() reports whether another integer remains and may be called repeatedly without advancing the iterator.
  • next() returns the next integer. It raises an iteration-exhausted exception when no value remains.
  • remove() is legal exactly once after each successful next() .
  • Calling remove() before next() , or calling it twice after the same next() , raises an illegal-state exception.
  • Removing an element must not cause the following element in the same row to be skipped.
  • Mutations made by remove() must be visible through the original nested list supplied to the constructor.

Example

data = [[], [1, 2, 3], [4, 5], [], [6]]
it = NestedIterator(data)

it.hasNext() -> true
it.next()    -> 1
it.next()    -> 2
it.remove()

data         -> [[], [1, 3], [4, 5], [], [6]]
it.next()    -> 3

Constraints

  • The outer and inner arrays exist for the lifetime of the iterator.
  • Clients do not mutate the nested arrays except through this iterator's remove() .
  • Values may repeat; position, not value, identifies what must be removed.
  • Empty outer input is valid.

Hints

  • Maintain a row and column for the next candidate, plus the exact position last returned.
  • Centralize skipping of empty or exhausted rows in one helper.
  • Deleting from the same row shifts later columns left; adjust the cursor accordingly.

Discussion Extensions

  • Give the amortized cost of traversal and the cost of removal for array-backed rows.
  • How would fail-fast behavior work if external mutation had to be detected?
  • What changes if inner collections are linked lists rather than arrays?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 9,000+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.