You are viewing a single comment's thread. Return to all 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"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Grid Challenge
You are viewing a single comment's thread. Return to all comments →