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.
Here, first we are traversing to the leftmost part of the tree and with it keeping a count.Once, we reach the leftmost part, we start printing the nodes,and come out of the function,to its root(recursion).As we travel downwards to the left, the value of count goes on decreasing,count-1 every node it travels.Hence, it willn't go to the right side of the node until and unless the count becomes zero or >0, which is the root of the tree. From there, it travels the right side of the tree.But here, it prints the data first and then goes to its right node.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree : Top View
You are viewing a single comment's thread. Return to all comments →
Here, first we are traversing to the leftmost part of the tree and with it keeping a count.Once, we reach the leftmost part, we start printing the nodes,and come out of the function,to its root(recursion).As we travel downwards to the left, the value of count goes on decreasing,count-1 every node it travels.Hence, it willn't go to the right side of the node until and unless the count becomes zero or >0, which is the root of the tree. From there, it travels the right side of the tree.But here, it prints the data first and then goes to its right node.