Organizing Containers of Balls

  • + 0 comments

    Python simply checking if a matching space container is there for every type of ball, worked out quite well, but I'm not sure about the complexities.

    This one doesn't require that much space so if anyone can tell me if and where I can improve heavily on time complexity:

    def organizingContainers(container):
        # Write your code here
        balls_in_container = sorted([ sum(container[i]) for i in range(len(container))])
        
        # count no of each type of ball
        n = len(container)
        freq_types = { x : 0 for x in range(n)}
     
        for i in range(n):
            for j in range(n):
                freq_types[j] += container [i][j]
        
        balls_types = sorted([freq_types[i] for i in range(n)])
        
        
        if balls_types == balls_in_container:
            return 'Possible' 
        else: 
            return 'Impossible'