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.
importjava.util.ArrayList;importjava.util.List;importjava.util.Scanner;publicclassCountingSortStrings{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);intn=scanner.nextInt();// Initialize the counting arrayList<List<String>>countingArray=newArrayList<>();for(inti=0;i<100;i++){countingArray.add(newArrayList<>());}// Read and sort the input stringsfor(inti=0;i<n;i++){intnum=scanner.nextInt();Stringstr=scanner.next();// If it's in the first half, replace the string with a dashif(i<n/2){countingArray.get(num).add("-");}else{countingArray.get(num).add(str);}}// Print the sorted stringsfor(List<String>list:countingArray){for(Stringstr:list){System.out.print(str+" ");}}scanner.close();}}
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 →