We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Tree: Preorder Traversal
Tree: Preorder Traversal
Sort by
recency
|
453 Discussions
|
Please Login in order to post a comment
For many languages in selector it doesn't provide any boilerplate code and cannot be solved by reading input since you don't know how binary tree composed. How can I use hakkerrank to prepare for interview
In some languages like Kotlin it gives only a main fucntion which doesn't have a Node class. And there's no explanation how the single array, that the input is giving, is sorted... I spent hours trying to figure out what the tree from the input should look like and I was trying to write a function to create the tree with Node class... So then I switched to Java and saw that the node object is given...
void solve(Node* root) { if(root == NULL) { return; } cout<data<<" "; solve(root->left); solve(root->right); }
solve(root);
Why it was showing main method in this?
My Java 8 solutions
Recursive approach
Iterative approach