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.
Nice problem. The editorial C++ solution has one small bug. When using dfs to do the tree traversal, we should consider the max depth of the tree. The max depth could be n=300000 and it will cause the segmentation fault due to the maximum stack level limit. Luckily, no such cases in test data. I suggest everyone to use array or other algorithms to solve the tree traversal to avoid the segmentation fault.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Birjik and Nicole's Tree Game
You are viewing a single comment's thread. Return to all comments →
Nice problem. The editorial C++ solution has one small bug. When using dfs to do the tree traversal, we should consider the max depth of the tree. The max depth could be n=300000 and it will cause the segmentation fault due to the maximum stack level limit. Luckily, no such cases in test data. I suggest everyone to use array or other algorithms to solve the tree traversal to avoid the segmentation fault.