Back to problems

Binary Tree Level Order Stream Iterator

Object-Oriented Programming · Google · Medium

Problem Create an iterator that produces a binary tree's level-order traversal one level at a time. It must not traverse or materialize the entire tree before iteration begins. Each call to next() should return all node values belonging to the next level as a list. The hasNext() method should report whether at least one unreturned level remains. Design the iterator with attention to the time required for each individual operation and to efficient use of memory. Interface…

Checking your access…