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.
long combinations = 0;
// countries with one astronaut
long countriesWithOne = N - graph.getAllNodes().size();
// all other countries with more than one astronauts
List<Integer> countries = graph.mapRegions();
for (int i = 0; i < countries.size(); i++) {
for (int j = i + 1; j < countries.size(); j++) {
combinations += countries.get(i) * countries.get(j);
}
combinations += countries.get(i) * countriesWithOne;
}
combinations += (countriesWithOne * (countriesWithOne - 1)) / 2;
System.out.println(combinations);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Journey to the Moon
You are viewing a single comment's thread. Return to all comments →
java 8, to pass case 11