-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGridChallenge.py
48 lines (35 loc) · 986 Bytes
/
GridChallenge.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
45
46
47
48
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'gridChallenge' function below.
#
# The function is expected to return a STRING.
# The function accepts STRING_ARRAY grid as parameter.
#
def gridChallenge(grid):
# Write your code here
for i in range(len(grid)):
# Sort characters in each row
grid[i] = ''.join(sorted(grid[i]))
# Check if columns are in ascending alphabetical order
for j in range(len(grid[0])):
for i in range(1, len(grid)):
if grid[i][j] < grid[i-1][j]:
return "NO"
return "YES"
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
grid = []
for _ in range(n):
grid_item = input()
grid.append(grid_item)
result = gridChallenge(grid)
fptr.write(result + '\n')
fptr.close()