Please enter your email address or userHandle.
Given a binary tree, find its preorder traversal.
Output: 1 4 4 2
Output: 6 3 1 2 2
You just have to complete the function preorder() which takes the root node of the tree as input and returns an array containing the preorder traversal of the tree.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
1 <= Number of nodes <= 104
0 <= Data of a node <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
want to view the editorial?
Login to access your submissions.