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.
defgridChallenge(grid):# Sort each rowforidxinrange(len(grid)):strList=list(grid[idx])strList.sort()grid[idx]="".join(strList)# Join all grid list to a single stringstrJoin="".join(grid)gLength=len(grid)# Create the column list based on grid lengthreverseGrid=[0]*len(grid)foriinrange(len(strJoin)):# get the ascii codecurr=ord(strJoin[i])# Get the saved grid ascii code based on index % lengthprev=reverseGrid[i%gLength]diff=curr-prev# if the diff < 0, means current ascii value less than previous, which means it's not in orderifdiff<0:return"NO"reverseGrid[i%gLength]=currreturn"YES"
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 →
My solution, it might complex