Binary Tree Inorder Traversal
Binary Tree Inorder Traversal
Given a binary tree in level-order representation, perform an inorder traversal (Left → Root → Right) and print the node values. Your solve(...) function receives these inputs directly as ready-made arguments — no input reading or parsing needed. Just compute and return the answer. Example: level-order [1 2 3 4 5 -1 -1] → inorder "4 2 5 1 3"
Input format — only if your code reads from stdin
Input format (stdin): - First line: integer n (number of values in level-order array) - Second line: n space-separated values, where -1 represents a null (absent) node Output: the node values visited in inorder sequence, space-separated.
Approach
Build the tree from level-order input using a queue. Then run recursive inorder: visit left subtree first, then root, then right subtree. Skip -1 nodes (they represent null). Collect all values and print space-separated.
Input
Output
- •
0 ≤ n ≤ 100 (meaning tree has at most ~50 actual nodes), -100 ≤ node values ≤ 100
More Trees problems
Browse all coding problems →Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards