-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.py
44 lines (32 loc) · 1.09 KB
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the organizingContainers function below.
def organizingContainers(container):
row = [0] * n #row array of zeros
col = [0] * n #col array of zeros
for i in range(n):
for j in range(n):
# adding balls in row column wise. We are taking sum for both row and column wise.
row[i] += container[i][j]
col[i] += container[j][i]
# Sort row and col, else some numbers may mismatch because of the arrangements. If we sort the arrays, we will have the numbers in equal order
if sorted(row) == sorted(col):
return "Possible"
else:
return "Impossible"
# Driver code
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
q = int(input())
for q_itr in range(q):
n = int(input())
container = []
for _ in range(n):
container.append(list(map(int, input().rstrip().split())))
result = organizingContainers(container)
fptr.write(result + '\n')
fptr.close()