• + 0 comments

    java 8, to pass case 11

        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);