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.
Tough one.
DFS for depth building, LCA for path finding (using depth), trying to put node with most connections at the root of the tree, simple math for sums (will fit in normal int), optimized visited nodes storage.
Tried caching paths (no improvement).
Still getting 8 timeouts (TCs: 5,6,8,9,11,14,15,17) :(
Undoubtedly there's another algo or structure I need to use.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting On a Tree
You are viewing a single comment's thread. Return to all comments →
Tough one. DFS for depth building, LCA for path finding (using depth), trying to put node with most connections at the root of the tree, simple math for sums (will fit in normal int), optimized visited nodes storage. Tried caching paths (no improvement). Still getting 8 timeouts (TCs: 5,6,8,9,11,14,15,17) :(
Undoubtedly there's another algo or structure I need to use.