-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_1431.java
More file actions
26 lines (25 loc) · 1.1 KB
/
Copy pathproblem_1431.java
File metadata and controls
26 lines (25 loc) · 1.1 KB
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
/*
1431. Kids With the Greatest Number of Candies
There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have.
Return a boolean array result of length n, where result[i] is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.
Note that multiple kids can have the greatest number of candies. */
class problem_1431 {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
List<Boolean> result = new ArrayList<>();
int sum,max = max_candy(candies);
for(int i=0;i<candies.length;i++){
sum = candies[i] + extraCandies;
result.add(sum>=max);
}
return result;
}
int max_candy(int[] candies){
int max = candies[0];
for(int i = 1;i<candies.length;i++){
if(max<candies[i]){
max = candies[i];
}
}
return max;
}
}