We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importosdefgridChallenge(grid):# Sort each row of the gridsorted_grid=[''.join(sorted(row))forrowingrid]# Check if each column is sortedn=len(sorted_grid)forcolinrange(len(sorted_grid[0])):forrowinrange(1,n):ifsorted_grid[row][col]<sorted_grid[row-1][col]:return"NO"return"YES"if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')t=int(input().strip())fort_itrinrange(t):n=int(input().strip())grid=[]for_inrange(n):grid_item=input()grid.append(grid_item)result=gridChallenge(grid)fptr.write(result+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Grid Challenge
You are viewing a single comment's thread. Return to all comments →