Grid Challenge Discussions | | HackerRank

Grid Challenge

Sort by

recency

|

451 Discussions

|

  • + 0 comments

    "Given a square grid of characters"

    But the test cases are not square grids?

  • + 0 comments

    TS or JS solution

    function gridChallenge(grid: string[]): string {
        let newG = grid.map((g) => {
            return g.split("").sort()
        })
        
        let row = newG.length
        let col = newG[0].length
    
        for (let i = 0; i < col; i++) {
            for (let j = 1; j < row; j++) {
                if (newG[j -1 ][i] > newG[j][i]) {
                    return 'NO'
                }
            }
        }
        
        return 'YES'
    }
    
  • + 0 comments

    desc or one of the test cases is wrong , its not giving square grid

  • + 0 comments

    Java solution with nested for loops and additional for loop for sorting strings. Any suggestions with better time complexity?

        public static String sortString(String s){
            char [] charArr = s.toCharArray();
            Arrays.sort(charArr);
            return new String(charArr);
        }
    
        public static String gridChallenge(List<String> grid) {
           ArrayList<String> stringArr = new ArrayList<>();
           for(int i = 0; i < grid.size(); i++){
            String s = sortString(grid.get(i));
            stringArr.add(s);
           }
           int stringSize = stringArr.get(0).length();
           for(int i = 1; i < stringArr.size(); i++){
            for(int j = 0; j < stringSize; j++){
                if(stringArr.get(i-1).charAt(j) > stringArr.get(i).charAt(j)){
                    return "NO";
                }
            }
           }
           return "YES";
        }
    
  • + 1 comment

    Description is innacurate. It sates a square matrix but one of the tests is a rectangular matrix.