We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
String[][] sortedGrid = new String[grid.size()][grid.size()];
for (int i = 0; i<grid.size(); i++) {
String[] sorted = grid.get(i).split("");
Arrays.sort(sorted);
sortedGrid[i] = sorted;
// *Immediately compare with previous row so you don't have to compare everything at last!*
if (i!=0) {
for (int j=0; j<sorted.length; j++) {
if (sortedGrid[i][j].compareTo(sortedGrid[i-1][j]) < 0) {
return "NO";
}
}
}
}
return "YES";
}
}
Cookie support is required to access HackerRank
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:
public static String gridChallenge(List grid) {
}