Nested List Iterator with Remove
Reported by candidates from Airbnb's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at this Airbnb problem is letting HAS_NEXT quietly move your cursor and lose track of which element REMOVE is supposed to delete. It was reported in July 2026, and it's a pure simulation of a nested iterator with a remove operation. Nothing fancy algorithmically. The whole difficulty is bookkeeping: row index, column index, and a record of the last returned element. If you've got an OA invite for Airbnb, this is the kind of task where one off-by-one fails three hidden tests. StealthCoder is the safety net if you blank mid-assessment.
The problem
You are given a mutable nested sequence lists, represented as an array of integer arrays, and a finite array operations. Simulate an iterator that visits the integers in row-major order. The supported operations follow these rules: HAS_NEXT returns whether another integer exists. It skips empty and exhausted rows, consumes no integer, and may be called repeatedly. NEXT returns the next integer. If the iterator is exhausted, it throws a no-next-element error. REMOVE deletes from lists the value returned by the most recent successful NEXT. It may succeed at most once for that successful NEXT. Calling it before any successful NEXT, or calling it twice for the same result, throws an illegal-remove error. A failed NEXT does not revoke the still-unused removal right from the most recent successful NEXT. Calling HAS_NEXT also does not revoke that right. When removal happens in the row currently being scanned, adjust the row cursor so the element that shifted into the removed position is not skipped. Finite operation adapter Return one string for every operation, followed by one final state string: HAS_NEXT contributes "true" or "false". A successful NEXT contributes the returned integer in decimal form; an exhausted call contributes "ERROR:no-next". A successful REMOVE contributes "removed"; an illegal call contributes "ERROR:remove". The last result is "STATE:" followed by the final nested arrays in compact JSON notation, including empty rows. Function runNestedIterator(lists: int[][], operations: String[]) → String[] Examples Example 1 lists = [[1,2],[],[3]] operations = ["HAS_NEXT","HAS_NEXT","NEXT","REMOVE","HAS_NEXT","NEXT","NEXT","HAS_NEXT"] return = ["true","true","1","removed","true","2","3","false","STATE:[[2],[],[3]]"] The repeated checks do not consume 1. Removing 1 shifts 2 into column zero, so the cursor moves back and 2 remains the next value. The empty middle row is skipped. Example 2 lists = [[5],[],[6,7]] operations = ["REMOVE","NEXT","HAS_NEXT","REMOVE","NEXT","REMOVE","REMOVE","NEXT","NEXT"] return = ["ERROR:remove","5","true","removed","6","removed","ERROR:remove","7","ERROR:no-next","STATE:[[],[],[7]]"] The first removal is illegal. After 5, HAS_NEXT advances across the empty row to find 6, but removing 5 is still legal. Removing 6 adjusts the cursor so 7 is not skipped. Example 3 lists = [[9]] operations = ["NEXT","NEXT","REMOVE","HAS_NEXT"] return = ["9","ERROR:no-next","removed","false","STATE:[[]]"] The failed second NEXT does not consume a value or revoke the unused removal right for 9. Removing it leaves the sole row empty. Constraints 0 <= lists.length <= 1000 Each row may be empty, and the total number of integers is at most 5000. Every integer is in [-10^9, 10^9]. 1 <= operations.length <= 5000 Every operation is HAS_NEXT, NEXT, or REMOVE. The returned array has exactly operations.length + 1 strings.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to separate two things: the scanning cursor and the removal target. Store the row and column of the last successful NEXT as its own pair, plus a canRemove flag. HAS_NEXT only advances the scanning cursor past empty or exhausted rows. It never touches the removal pair or the flag. NEXT on success sets the pair and flag, then advances the column. REMOVE deletes at the stored pair, clears the flag, and if the removal row is the row being scanned, decrements the column so the shifted element isn't skipped. The common pitfall is removing at the current cursor after HAS_NEXT has jumped rows, which deletes the wrong value. Another is clearing the flag on a failed NEXT. Copy the lists so you mutate safely, then serialize the final state with empty rows kept. If you freeze on the cursor adjustment during the live OA, StealthCoder can hand you the working structure.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Nested List Iterator with Remove cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Airbnb's OA.
Airbnb reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Nested List Iterator with Remove FAQ
What's the trick in Nested List Iterator with Remove?+
Track the last returned element's row and column separately from the scanning cursor. HAS_NEXT moves the scanner only. REMOVE uses the saved position, then pulls the column back by one if the removed element sits in the row being scanned.
How hard is this Airbnb OA question really?+
Algorithmically easy, since it's linear simulation with no clever data structure. It's hard to get fully correct because of the edge cases: empty rows, repeated HAS_NEXT, failed NEXT, and double REMOVE. Expect to lose time on those, not on the idea.
Does HAS_NEXT or a failed NEXT cancel the right to remove?+
No. Per the statement, neither revokes an unused removal right from the most recent successful NEXT. Only a successful REMOVE clears it, and a new successful NEXT replaces it with a fresh one. Example 3 shows this exactly.
How do I format the final STATE string?+
Output STATE: followed by compact JSON of the nested arrays, no spaces, and keep empty rows as []. Example: STATE:[[2],[],[3]]. Build it by hand with joins rather than relying on a library that adds spaces.
How do I prepare for this in 48 hours?+
Write the iterator yourself once, then run the three given examples by hand. Add tests for an empty lists array, all-empty rows, and REMOVE as the very first operation. Those cases cover most hidden failures for this problem.