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.
Recursive solution doesn't work on Python because of the maximum recursion limit (e.g. Test 11 has a tree with 72000 depth). sys.setrecursionlimit(100000) doesn't work because Python still crashes at ~2670 level of recursion. What works: using Kahn's algorithm to iteratively go from the leaves to the root. New style Prescription wooden glasses
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Kingdom Division
You are viewing a single comment's thread. Return to all comments →
Recursive solution doesn't work on Python because of the maximum recursion limit (e.g. Test 11 has a tree with 72000 depth). sys.setrecursionlimit(100000) doesn't work because Python still crashes at ~2670 level of recursion. What works: using Kahn's algorithm to iteratively go from the leaves to the root. New style Prescription wooden glasses