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.
classArstr{privateintpos;privateStringstr;publicArstr(Integeri,Strings1){this.pos=i;this.str=s1;}publicintgetpos(){returnthis.pos;}publicStringgetstr(){returnthis.str;}}classResult{/* * Complete the 'countSort' function below. * * The function accepts 2D_STRING_ARRAY arr as parameter. */publicstaticvoidcountSort(List<List<String>>arr){// Write your code hereList<Arstr>res=newArrayList<>();Comparator<Arstr>comp=newComparator<Arstr>(){@Overridepublicintcompare(Arstro1,Arstro2){return(o1.getpos()-o2.getpos());}};for(inti=0;i<arr.size();i++){if(i<arr.size()/2){res.add(newArstr(Integer.valueOf(arr.get(i).get(0)),"-"));}else{res.add(newArstr(Integer.valueOf(arr.get(i).get(0)),arr.get(i).get(1)));}}Collections.sort(res,comp);for(Arstra:res){System.out.print(a.getstr()+" ");}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →
Using comparator and a custom class :