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.
Journey to the Moon
Journey to the Moon
Sort by
recency
|
519 Discussions
|
Please Login in order to post a comment
class UnionFind { public: vector parent, size;
};
long journeyToMoon(int n, vector>& astronaut) { UnionFind uf(n);
can anyone suggest what's is wrong one test case is faling?
}
Nice breakdown of the issue and clear grasp of how to identify connected components for the Journey to the Moon problem on HackerRank via DFS or union-find roller lip . Your suggestion to use prefix sums when calculating cross-country pairs is spot on and avoids overflow issues too.
Javascript
Using union_find is more efficient than using graph.
Test case 11 does not pass. All others pass.
Solution using DFS.