-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhiringProblemJava.java
39 lines (32 loc) · 1.07 KB
/
hiringProblemJava.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
import java.util.*;
public class hiringProblemJava {
public static void main(String args[]){
ArrayList<Integer> candidateList = new ArrayList<Integer>();
candidateList.add(1);
candidateList.add(2);
candidateList.add(3);
candidateList.add(4);
candidateList.add(5);
int currentCandidate = candidateList.get(0);
int hiringCost = 1;
for(int i=1; i<5; i++){
if (candidateList.get(i) > currentCandidate){
currentCandidate = candidateList.get(i);
hiringCost +=1;
}
}
System.out.println(hiringCost);
System.out.println(candidateList);
Collections.shuffle(candidateList);
currentCandidate = candidateList.get(0);
hiringCost = 1;
for(int i=1; i<5; i++){
if (candidateList.get(i) > currentCandidate){
currentCandidate = candidateList.get(i);
hiringCost +=1;
}
}
System.out.println(hiringCost);
System.out.println(candidateList);
}
}