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.
public static void countSort(List> arr) {
int n = arr.size();
int middle = n / 2;
StringBuilder sb = new StringBuilder();
Entry[] entries = new Entry[n];
for (int i = 0; i < n; i++) {
String key = arr.get(i).get(0);
String value = (i < middle) ? "-" : arr.get(i).get(1);
entries[i] = new Entry(key, value);
}
Arrays.sort(entries, Comparator.comparing(entry -> Integer.parseInt(entry.number)));
for (Entry e : entries) {
sb.append(e.letters).append(" ");
}
System.out.print(sb.toString());
}
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 →
My java Solution
public static void countSort(List> arr) { int n = arr.size(); int middle = n / 2; StringBuilder sb = new StringBuilder(); Entry[] entries = new Entry[n];