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.
plese anyone guide me in this code where i am doing mistke
public static List countingSort(List arr) {
// Write your code here
//find the max and min in the given list
if(arr==null || arr.isEmpty()){
return new ArrayList<>();
}
int max = arr.get(0);
int min = arr.get(0);
for (int num : arr) {
if (num > max) {
max = num;
}
if (num < min) {
min = num;
}
}
int range = max-min + 1;
List<Integer>list= new ArrayList<>();
for (int i = 0; i < range; i++) {
list.add(0);
} // store the count of the element
for (int num : arr) {
list.set(num - min, list.get(num - min) + 1);
}
return list;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 1
You are viewing a single comment's thread. Return to all comments →
plese anyone guide me in this code where i am doing mistke public static List countingSort(List arr) { // Write your code here //find the max and min in the given list if(arr==null || arr.isEmpty()){ return new ArrayList<>(); }