- Prepare
- Algorithms
- Greedy
- Grid Challenge
- Discussions
Grid Challenge
Grid Challenge
+ 7 comments As far my knowledge , I cannot find any greedy pattern here. Greedy solution is to pick the optimal solution at that point. Correct me if I am wrong.
+ 3 comments Isn't it that the given grid should be a square grid ? , but there are test cases where the grid is not a square matrice. E.g in test case 1:
3 mpxz abcd wlmf 4 abc hjk mpq rtv
+ 1 comment Test cases contain mixed end of lines, sometime there is "\r" in the end, sometime there is none. Had to spend hackos to find this. Please fix the test cases (at least case#4).
+ 5 comments I solved the problem. I'm getting all right except the test case 10. I checked the results by running on my computer and compared with the actual results. It is right as well, but it is showing wrong answer. can you please let me know why ?
https://www.hackerrank.com/challenges/grid-challenge/submissions/code/3052512
+ 6 comments python solution
the thing that outrages me is the initial code is not correct.
you need to add a for loop for t instead of just read it as the code initiated.
#!/bin/python import sys def gridChallenge(grid): for i in range(n): grid[i] = sorted(grid[i]) for i in range(n-1): for j in range(n): if grid[i][j]>grid[i+1][j]: return "NO" return "YES" if __name__ == "__main__": t = int(raw_input().strip()) for _ in range(t): n = int(raw_input().strip()) grid = [] grid_i = 0 for grid_i in xrange(n): grid_t = str(raw_input().strip()) grid.append(grid_t) print gridChallenge(grid)
Sort 504 Discussions, By:
Please Login in order to post a comment