Dsa
Trees
Warm-up
Inorder Traversal
Given the root of a binary tree, return its inorder traversal as a list of values. Inorder traversal is performed by visiting the left subtree, then the root node, and finally the right subtree.
Input Format:
- The input starts with an integer n, the number of nodes in the tree.
- The next n lines contain an integer followed by two integers representing the left and right children (or -1 if there is no child).
Output Format:
- A space-separated string of integer values representing the inorder traversal of the binary tree.
Example Input:
3
1 2 3
2 -1 -1
3 -1 -1
Example Output:
2 1 3
Key concepts
treestraversalinorder
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now