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.
- Counting Sort 1
- Discussions
Counting Sort 1
Counting Sort 1
Sort by
recency
|
695 Discussions
|
Please Login in order to post a comment
Java
Java 8:
public static List countingSort(List arr) { Map countMap = new HashMap<>(); List result = new ArrayList<>(); for (int i = 0; i< 100; i++) { countMap.put(i, 0); }
for (int num : arr) { int value = countMap.get(num); countMap.put(num, value + 1); }
for (int i = 0; i < 100; i++) { result.add(countMap.get(i)); }
return result;
}
In the question description, the input format is as follows:
Input Format
The first line contains an integer , the number of items in . Each of the next lines contains an integer where .
If you solve it with C++, its input is a vector and the size() tells you what N is.
So there is no first line input.
Scala solution