Grid Challenge Discussions | | HackerRank

Grid Challenge

Sort by

recency

|

96 Discussions

|

  • + 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...

  • + 0 comments

    Java Solution

        public static String gridChallenge(List<String> grid) {
            for (int i=0; i < grid.size(); i++) {
                String element = grid.get(i);
                String sortedEl = Stream.of(element.split(""))
                        .sorted().collect(Collectors.joining());
                grid.set(i, sortedEl);
            }
            
            boolean sorted = true;
            for (int j=0; j < grid.get(0).length(); j++) {
                List<String> myList = new ArrayList<>();
                for (int k=0; k < grid.size(); k++) {
                    myList.add(grid.get(k).substring(j, j+1));
                }
                String original = String.join("", myList);
                Collections.sort(myList);
                String sortedStr = String.join("", myList);
                sorted = !original.equals(sortedStr) ? false : sorted;
            }
            return sorted ? "YES" : "NO";
        }