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.
Actually the problem being tested with the test cases is easy. However if you try to solve the problem as defined in GFC, I'd agree that it's not that easy. I actually spent some time trying to solve what GFC describes, but I couldn't get all the test cases to work. When I debugged some of the test cases, I realized that the test cases were all for the simplified case. I then modified my code to support that, and all test cases passed.
After I got all the test cases to work, I actually looked at the editorial, and found the following.
Note: This solution is overly simplified and you will need something more complicated for certain types of imbalanced trees.
Basically the actual problem statement was not well defined. Either the test cases should support all types of trees, and the problem could potentially be made a medium problem. Or the note should have been put in the problem statement, instead of the editorial.
Tree : Top View
You are viewing a single comment's thread. Return to all comments →
This question is just about printing the outermost left or right nodes .. java code (its a version of what parmarabhishek_1 told https://www.hackerrank.com/challenges/tree-top-view/forum/comments/331313 )
java code
you are right.
Actually the problem being tested with the test cases is easy. However if you try to solve the problem as defined in GFC, I'd agree that it's not that easy. I actually spent some time trying to solve what GFC describes, but I couldn't get all the test cases to work. When I debugged some of the test cases, I realized that the test cases were all for the simplified case. I then modified my code to support that, and all test cases passed.
After I got all the test cases to work, I actually looked at the editorial, and found the following.
Note: This solution is overly simplified and you will need something more complicated for certain types of imbalanced trees.
Basically the actual problem statement was not well defined. Either the test cases should support all types of trees, and the problem could potentially be made a medium problem. Or the note should have been put in the problem statement, instead of the editorial.
this will only pass the 1st test case. i thougth the same logic and i implemented it in c++.
Will not pass the 2nd TCs :)
This only passes the sample and first test case