Grid Challenge Discussions | | HackerRank

Grid Challenge

Sort by

recency

|

97 Discussions

|

  • + 0 comments
    public static String gridChallenge(List<String> grid) {
    // Write your code here
        List<String> squareMatrixList = new ArrayList<>();
        //row sorting
        for(int i =0; i < grid.size(); i ++){
           char[] rowsorted = grid.get(i).toCharArray();
           Arrays.sort(rowsorted);
           squareMatrixList.add(String.valueOf(rowsorted));
        }
        System.out.println(squareMatrixList.toString());
        int size = squareMatrixList.size();
        int strLength = squareMatrixList.get(0).length();
        for(int col =0; col < strLength; col++){
            for(int row = 0; row < size -1; row++){
                String str1 = squareMatrixList.get(row);
                String str2 = squareMatrixList.get(row +1);
                if(str1.charAt(col) > str2.charAt(col)){
                    return "NO";
                }
            }
        }
        return "YES";
    }
    
  • + 0 comments

    Python solution

    def gridChallenge(grid):
        sorted_grid = ["".join(sorted(row)) for row in grid]
        num_cols = len(sorted_grid[0])
        num_rows = len(sorted_grid)
        
        for col_idx in range(num_cols):
            columns = []
            for row_idx in range(num_rows):
                columns.append(sorted_grid[row_idx][col_idx])
           
            if columns != sorted(columns):
                return "NO"
        return "YES"
    
  • + 0 comments

    Test case contains non-square grid which violates task description

  • + 0 comments

    I love this platform. OnlyTestcase 10 fails. It has 100 inputs, with HUGE size. I try to copy the input into custom output to try to see the difference in my answer. Error, input size too big.

    Okay thank you. ><

  • + 0 comments

    Somehow this grid is not square, even though they say so...