class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
int MAX=0;
for (int candy : candies) {
MAX = Math.max(candy, MAX);
}
List<Boolean> ans=new ArrayList<>();
for (int i=0; i<candies.length;i++) {
if (candies[i]+extraCandies>=MAX) ans.add(i,true);
else ans.add(i,false);
}
return ans;
}
}
I wanted a faster code, and studied with a code in the discussion tab. That person used stream.
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
int max= Arrays.stream(candies).max().getAsInt();
return Arrays.stream(candies).mapToObj(candy->candy+extraCandies>=max).collect(Collectors.toList());
}
}