515. Find Largest Value in Each Tree Row (BFS)

time: O(n)

space: O(D) to keep the queues, where D is a tree diameter. Let's use the last level to estimate the queue size. This level could contain up to N/2N/2 tree nodes in the case of complete binary tree.

Last updated

Was this helpful?