You are given a ‘Binary Tree’.
Return the preorder traversal of the Binary Tree.
Input: Consider the following Binary Tree:
Output:
Following is the preorder traversal of the given Binary Tree: [1, 2, 5, 3, 6, 4]
1 2 3 5 4 6 7 -1 -1 -1 -1 -1 -1 -1 -1
1 2 5 4 3 6 7
The Binary Tree given in the input is as follows:
5 6 10 2 3 -1 -1 -1 -1 -1 9 -1 -1
5 6 2 3 9 10
The Binary Tree given in the input is as follows:
Try to do this in O(n).
1 <= n <= 100000
where 'n' is the number of nodes in the binary tree.
Time Limit: 1 sec