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.
publicstaticStringgridChallenge(List<String>grid){booleanisSorted=true;// sort and reinsert stringsfor(Stringstr:grid){StringsortedStr=sortedString(str);grid.set(grid.indexOf(str),sortedStr);}// check each char in the row < the char in the row belowfor(intcol=0;col<grid.get(0).length();col++){for(introw=0;row<grid.size()-1;row++){if(grid.get(row).charAt(col)>grid.get(row+1).charAt(col))isSorted=false;}}returnisSorted?"YES":"NO";}publicstaticStringsortedString(Strings){char[]chars=s.toCharArray();Arrays.sort(chars);returnnewString(chars);}
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 →
Readable Java 8 Solution: