You are viewing a single comment's thread. Return to all comments →
Java 15
public static String gridChallenge(List<String> grid) { final String YES = "YES"; final String NO = "NO"; int columnCount = grid.get(0).length(); int rowCount = grid.size(); var sortedRowsGrid = grid.stream() .map(row -> row.chars().sorted().mapToObj(num -> (char) num).collect(toList()) ).collect(toList()); for (int j = 0; j < columnCount; j++) { for (int i = 1; i < rowCount; i++) { char currentLetter = sortedRowsGrid.get(i).get(j); char previousLetter = sortedRowsGrid.get(i - 1).get(j); if (currentLetter < previousLetter) { 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 →
Java 15