• + 0 comments

    This works for the test case but runs out of time in other cases. I am seeing overly complicated solutions and not many of those. The solution cannot be so complicated.

    def king(army, k):
        # Write your code here
        ways = 20
        countries = k
        detachments = 0
        if not len( army) > 0:
            return 0
        if not k > 0:
            return 0
        
        for index, soldiers in enumerate(army):
            for x in range(index+1, len(army)):
                # combinations
                detachments1 = math.comb( soldiers, 4) +1
                detachments2 = math.comb( army[x],4) +1
                detachments += detachments1 * detachments2
    
    
                
        return( int(detachments % (10E9+7)))