MicrosoftMediumTree / BFS
Binary Tree Level Order Traversal
Software Engineer
Problem
Given a binary tree, return the level order traversal of its nodes.
Example
Input: root = [3,9,20,null,null,15,7] Output: [[3],[9,20],[15,7]]
Approach
Use BFS with a queue.
Complexity
Time: O(n)
Space: O(n)
Solution
def levelOrder(root):
...