← Questions

Flatten a nested list iterator

0
AirbnbCodingLast asked Apr 2026

A list holds integers and other lists, nested to any depth. Write an iterator with next() and has_next() that returns the integers in order. Do it lazily with a stack of positions rather than flattening everything up front, and make sure empty inner lists are skipped.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding