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.
I just finished solving this problem and have a couple of comments/suggestions. First, I agree with several of the comments expressed so far: it's not clear in the problem description that an undirected graph is provided as input instead of a tree, and one has to make the working assumption that the first node provided is the root of the tree to work with. It would be great if these two points could be clarified for future enthusiasts/hackers that try to solve the problem.
Second (and this issue may have to do more with HackerRank's platform than with this problem in particular), my solution (written in Python) was failing for test cases 6 and above due to the size of the input graph. However, the only message I was getting about it was "Runtime error", which is rather cryptic in this case. Hadn't I downloaded one of the bigger test cases and run it in my computer, I wouldn't have figured out that the problem was that I was running out of memory and that I needed to devise an iterative solution instead of a recursive one.
I hope these comments/suggestions are taken in good faith; my only intention is to help improve the quality of the site.
Cut the Tree
You are viewing a single comment's thread. Return to all comments →
I just finished solving this problem and have a couple of comments/suggestions. First, I agree with several of the comments expressed so far: it's not clear in the problem description that an undirected graph is provided as input instead of a tree, and one has to make the working assumption that the first node provided is the root of the tree to work with. It would be great if these two points could be clarified for future enthusiasts/hackers that try to solve the problem.
Second (and this issue may have to do more with HackerRank's platform than with this problem in particular), my solution (written in Python) was failing for test cases 6 and above due to the size of the input graph. However, the only message I was getting about it was "Runtime error", which is rather cryptic in this case. Hadn't I downloaded one of the bigger test cases and run it in my computer, I wouldn't have figured out that the problem was that I was running out of memory and that I needed to devise an iterative solution instead of a recursive one.
I hope these comments/suggestions are taken in good faith; my only intention is to help improve the quality of the site.
Cheers, Gaston