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.
Hey!! I just walked through ur solution and man, was that brilliant! :) so very thoughtful of you. I have a couple of doubts, though.
Isn't "*thisnode" will be created everytime the loop runs? Wouldn't that have a slightly more effect on space complexity? Also, The while loop runs even though there are no nodes left in the tree (i.e., when both the if conditions return false). It runs few times just to prove the while condition false (so that i becomes equal to n). Is that really necessary? Can't we stop as soon as both the if conditions fails with another "else if" of "if" statement?
I'd be really grateful if u helped me out. Thankyou.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Level Order Traversal
You are viewing a single comment's thread. Return to all comments →
Hey!! I just walked through ur solution and man, was that brilliant! :) so very thoughtful of you. I have a couple of doubts, though.
Isn't "*thisnode" will be created everytime the loop runs? Wouldn't that have a slightly more effect on space complexity? Also, The while loop runs even though there are no nodes left in the tree (i.e., when both the if conditions return false). It runs few times just to prove the while condition false (so that i becomes equal to n). Is that really necessary? Can't we stop as soon as both the if conditions fails with another "else if" of "if" statement?
I'd be really grateful if u helped me out. Thankyou.