Dsa
Trees
Warm-up
Level Order Traversal
Implement a function that performs level order traversal of a binary tree and returns the nodes in an array. If the tree is empty, return an empty array.
Input format:
A single line containing integers, the first integer is the number of nodes followed by node values in level order (use -1 for null nodes).
Output format:
Return a list of node values in level order.
Example:
Input:
5 1 2 3 4 -1 -1 -1
Output:
[1, 2, 3, 4]
Key concepts
treeslevel orderbinary trees
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