Counting Sort 1 HackerRank Solution


Counting Sort 1 HackerRank Solution
Source : https://www.hackerrank.com/challenges/countingsort1



Source : https://www.hackerrank.com/challenges/countingsort1


Solution


// Karthikalapati.blogspot.com
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
final int maxValue = 100;
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] array = new int[maxValue];
for (int i = 0; i < n; i++) {
int num = scan.nextInt();
array[num]++;
}
scan.close();
for (int i = 0; i < n; i++) {
System.out.print(array[i] + " ");
}
}
}

No comments:

Post a Comment