-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.java
45 lines (36 loc) · 1.16 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
// Read input from STDIN & Print output to STDOUT
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int [] sticks = new int[n];
for(int i = 0; i < n; i++)
{
sticks[i] = input.nextInt();
}
// QuickSort sticks array in ascending order
// The built in sort function performs a dual pivot quick sort that rarely degrades to n^2
Arrays.sort(sticks);
int sticksLeft = n;
int curr = sticks[0];
int currCount = 0;
System.out.println(n);
//Works by decrementing sticksLeft by the frequency of the smallest stick each time
for(int i = 0; i < n; i++)
{
if(curr == sticks[i])
{
currCount++;
}
else
{
sticksLeft -= currCount;
currCount = 1;
curr = sticks[i];
System.out.println(sticksLeft);
}
}
}
}