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
|
507 Discussions
|
Please Login in order to post a comment
The output for one of the test cases do not fit into int range for c++.
ans is 4999949998 but int represantation is not possible, which is return type of function
For test case 11, you expect the number will be long long, but in the provided code you defined in the main function with
int
. Very poor consideration.This is broken in C#. Everything needs to be longs.
Java solution below. You can find connectedness of the astronauts by continually doing BFS searches until you've run out of 'unvisited' astronauts. Set up the astronaut pairs as an adjacency list (you can think of the pairs as undirected edges) and for each BFS search, add the number of astronauts you found to a list. After you have a list of country counts, it's just a little bit of math to find the number of possible pairs. Also, one test case requires a long output, so change the output type to that. public static long journeyToMoon(int n, List> astronaut) { // Write your code here // n = num astronauts int numPairs = astronaut.size();
}
hell with pre-templated code in cpp.
Result can be longer than int but in given default main function of return type int.
Got Wrong Answer for it!!!!!!