Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5604 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3413 |
Complete Leaderboard | |
|
|
@codersgroup18 | 799 |
@sriramgoparaju99 | 737 |
@Manikanta punnam | 629 |
@rdakka | 606 |
@prankursharma31 | 597 |
@praveenbgp6 | 546 |
@sanskar94511 | 531 |
@purohitmn02 | 529 |
@yashkaril4 | 517 |
@abhikarshgupta | 474 |
@rohitgarg2825 | 464 |
Complete Leaderboard |
Given a Binary Tree, your task is to find its level order traversal.
For the below tree the output will be 1 $ 2 3 $ 4 5 6 7 $ 8 $.
1
/ \
2 3
/ \ / \
4 5 6 7
\
8
Example 1:
Input: 1 / 4 / \ 4 2 Output:1 $ 4 $ 4 2 $
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output: 10 $ 20 30 $ 40 60 $
Your Task:
This is a function problem. You don't need to read input. Just complete the function levelOrder() that takes nodes as parameter and returns level order traversal as a 2D list.
Note: The driver code prints the levels '$' separated.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
Constraints:
1 <= Number of edges <= 1000
0 <= Data of a node <= 100
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes