-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathstick.java
More file actions
34 lines (28 loc) · 918 Bytes
/
Copy pathstick.java
File metadata and controls
34 lines (28 loc) · 918 Bytes
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
package collectionFramework;
import java.util.*;
public class CutTheSticksHackerrank {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int arr[] = new int[n];
for(int arr_i=0; arr_i < n; arr_i++){
arr[arr_i] = in.nextInt();
}
int numberOfSticks = n;
while(numberOfSticks>0){
System.out.println(numberOfSticks);
int minPositive = 1000;
for(int i = 0 ;i<n;i++){
if(arr[i]<minPositive && arr[i]>0){
minPositive = arr[i];
}
}
for(int i = 0;i<n;i++){
arr[i] = arr[i] - minPositive;
if(arr[i]==0){
numberOfSticks--;
}
}
}
}
}