Skip to content

Commit 4a4b61c

Browse files
committed
2 parents b4b42e1 + de7820e commit 4a4b61c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Greedy/Grid Challenge/andrew.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Grid(object):
2+
def __init__(self, rows):
3+
self.rows = rows
4+
def canBeSorted(self):
5+
temp = []
6+
for row in self.rows:
7+
temp.append("".join(sorted(row)))
8+
# check columns
9+
for j in xrange(len(temp[0])):
10+
col = [temp[i][j] for i in xrange(len(self.rows))]
11+
if col != sorted(col):
12+
return False
13+
return True
14+
15+
def getInput():
16+
numTests = input()
17+
testcases = []
18+
for t in xrange(numTests):
19+
numRows = input()
20+
rows = []
21+
for row in xrange(numRows):
22+
rows.append(raw_input())
23+
testcases.append(Grid(rows))
24+
return testcases
25+
26+
if __name__ == "__main__":
27+
testcases = getInput()
28+
for testcase in testcases:
29+
if testcase.canBeSorted():
30+
print "YES"
31+
else:
32+
print "NO"

0 commit comments

Comments
 (0)