Organizing Containers of Balls

https://www.hackerrank.com/challenges/organizing-containers-of-balls/problem

每次交换并不会对桶里面球的数量造成变化。

那么经过任意次交换之后,要满足最终状态的话,必须满足A==B.

如果A!=B的话,比如A分别是[2,5]的话,而B是[3,4], 那么无论如何A[1]桶里面会多一种颜色的球。

def organizingContainers(container):
    n = len(container)
    a = [0] * n
    b = [0] * n
    for i in range(n):
        for j in range(n):
            a[i] += container[i][j]
            b[j] += container[i][j]

    a.sort()
    b.sort()
    ok = (a == b)
    ans = 'Possible' if ok else 'Impossible'
    return ans