Back to Practice
#0237
Binary Tree Inorder Traversal
EasyDSA18 min10 XP
Problem
A tree node is represented as [value, left, right], and an empty child is None. Return the inorder traversal values: left, root, right.
Why This Matters
Tree traversal is the foundation for BST checks, tree DP, recursion, and graph thinking.
Function Signature
def inorder(root):
Examples
Example 1
Inputroot = [2, [1, None, None], [3, None, None]]
Output[1, 2, 3]
Visit left subtree, then root value, then right subtree.
Constraints
- Return the exact requested value.
- Handle empty or small inputs when the prompt allows them.
- Prefer the target DSA pattern over brute force when the input can grow.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Balanced three nodes
Input[2, [1, None, None], [3, None, None]]
Expected[1, 2, 3]
Left-root-right gives sorted values for this BST.
Right leaning
Input[1, None, [2, None, [3, None, None]]]
Expected[1, 2, 3]
Empty left children are skipped.
Hidden Test Categories
empty treesingle nodeunbalanced tree