Grid Challenge Discussions | | HackerRank

Grid Challenge

Sort by

recency

|

87 Discussions

|

  • + 0 comments

    n clearly does not contain the number of row and columns in the grid, as the number of rows and columns can be different

  • + 0 comments

    Python 3 solution:

    from typing import Literal
    
    
    def gridChallenge(grid: list[str]) -> Literal["NO", "YES"]:
        _grid = iter(grid)
        last_row = sorted(next(_grid))
        for row in _grid:
            row = sorted(row)
            if any(i < j for i, j in zip(row, last_row)):
                return "NO"
            last_row = row
        return "YES"
    
  • + 0 comments

    Although it says it receives a square matrix, it doesn't. Code should work even when the grid is not square.

  • + 0 comments

    My Python solution given the fact that some test cases come with non-square grids

    def gridChallenge(grid):
        # Write your code here
        n = len(grid)
        sortedRows = [sorted(row) for row in grid]
        if len(sortedRows[0]) != n:
            m = len(sortedRows[0])
        else:
            m = n
        for i in range(m):
            for j in range(1, n):
                if sortedRows[j][i] < sortedRows[j-1][i]:
                    return 'NO'
        return 'YES'
    
  • + 0 comments

    `def gridChallenge(grid): # Write your code here fixed = list(map(lambda x: sorted(x), grid)) n = len(grid) for index in range(len(grid[0])): for i in range(n-1): if (ord(fixed[i][index]) > ord(fixed[i+1][index])): return "NO" return "YES"