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.
That's essentially my solution. In recursive form it's quite compact: two calls to DFS. But then you need to turn it into an iterative algorithm or you'll run out of recursion space. You still need to keep a stack of traces though or you'll lose information.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cut the Tree
You are viewing a single comment's thread. Return to all comments →
That's essentially my solution. In recursive form it's quite compact: two calls to DFS. But then you need to turn it into an iterative algorithm or you'll run out of recursion space. You still need to keep a stack of traces though or you'll lose information.