FastPrepBinary Tree Level Order Traversal

Binary Tree Level Order Traversal

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Return the tree values level by level from top to bottom. Within each level, list nodes from left to right.

Function

levelOrder(root: TreeNode) → int[][]

Examples

Example 1

root = [3,9,20,null,null,15,7]return = [[3],[9,20],[15,7]]

The root forms level zero, followed by its children and then the final two grandchildren.

Constraints

  • The tree contains between 0 and 10000 nodes.
  • Node values fit in a signed 32-bit integer.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[][] levelOrder(TreeNode root) {
  // Write your code here.
}
root[3,9,20,null,null,15,7]
expected[[3],[9,20],[15,7]]
Checking account…