-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaxCandies.java
28 lines (26 loc) · 956 Bytes
/
MaxCandies.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
/*
# Problem Statement: Count the max candies id the extra candies are given to a child in the array
---------------------------------------------------------------
# Approach :
- calculate the max of the array beforehand
- then apply a for loop and check if it is greater than max after adding the extra candies
- return true and false accordingly
---------------------------------------------------------------
*/
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
int max = Integer.MIN_VALUE;
for(int i=0;i<candies.length;i++) {
if(max < candies[i]) {
max = candies[i];
}
}
ArrayList<Boolean> arr = new ArrayList<Boolean>();
for(int i=0;i<candies.length;i++) {
if((candies[i]+extraCandies) >= max) {
arr.add(true);
} else {
arr.add(false);
}
}
return arr;
}