-
Notifications
You must be signed in to change notification settings - Fork 0
/
KidsWithCandies.java
36 lines (32 loc) · 1.03 KB
/
KidsWithCandies.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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class KidsWithCandies {
public static void main(String[] args) {
int[] kidsWithCandies = {12,1,12};
int extraCandies = 10;
boolean[] resutl = candies(kidsWithCandies,extraCandies);
for(boolean data : resutl){
System.out.println(data);
}
}
public static boolean[] candies(int[] kidsWithCandies, int extraCandies){
boolean[] result = new boolean[kidsWithCandies.length];
int currentMax = kidsWithCandies[0];
int i =1;
while (i< kidsWithCandies.length){
if(kidsWithCandies[i] > currentMax ){
currentMax = kidsWithCandies[i];
}
i++;
}
for (int j = 0; j < kidsWithCandies.length ; j++) {
result[j] = kidsWithCandies[j] + extraCandies >= currentMax ;
}
return result;
}
}