forked from RyanFehr/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
29 lines (27 loc) · 857 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Problem: https://www.hackerrank.com/challenges/countingsort3
//Java 8
/*
Time Complexity: O(n+k) //k is the total numbers and k is total unique numbers
Space Complexity: O(k) //we have to intialize an array to the number of unique numbers
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] frequencies = new int[100];
for(int i = 0; i < n; i++)
{
int num = input.nextInt();
input.nextLine();//throw away following string
frequencies[num] = frequencies[num] + 1;
}
int sum = 0;
for(int i = 0; i < frequencies.length; i++)
{
sum += frequencies[i];
System.out.print(sum+" ");
}
}
}