Introduction
So, here we are given an array. At first we have to figure out the max value of the array. Now we have to add the extraCandies value with index value and check whether it is larger or equal to max or not. If small store false otherwise true.
Examples
Steps
- Run a for loop and find the max value
- In the second loop check, if(candies[i] + extraCandies ≥ maximum) set true.
- Else set false
Hints
JavaCode
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
List<Boolean> list = new ArrayList<Boolean>();
int max = 0;
for(int i = 0; i<candies.length; i++){
if(max < candies[i]){
max = candies[i];
}
}
for(int i = 0; i<candies.length; i++){
if(candies[i] + extraCandies >= max){
list.add(true);
}
else{
list.add(false);
}
}
return list;
}
}
Top comments (0)