FastPrepBinary Tree Inorder Traversal

Binary Tree Inorder Traversal

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

Given the root of a binary tree, return its node values in inorder: left subtree, node, then right subtree.

Function

inorderTraversal(root: TreeNode) → int[]

Examples

Example 1

root = [1,null,2,3]return = [1,3,2]

Visit 1, then the left child 3 of node 2, then node 2.

Example 2

root = []return = []

An empty tree has an empty traversal.

Constraints

  • The tree has at most 10^5 nodes.
  • Node values are 32-bit signed integers.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] inorderTraversal(TreeNode root) {
  // Write your code here.
}
root[1,null,2,3]
expected[1,3,2]
Checking account…