Leetcode question 1431 Kids With the Greatest Number of Candies
This is a record on how I solved leetcode question 1431 kids with the greatest number of candies. The goal is output a List that contains if the specific kid is going to get the greatest number of candies. The term greatest here is defined as the maximum number of candies any kid has before adding the extra candies. So, first is to get the "greatest" value, via a loop, or using Collections.max() but I never got it working. Then use another loop to append to the List variable. Here's the code: class Solution { public List < Boolean > kidsWithCandies ( int [] candies , int extraCandies ) { List < Boolean > high = new ArrayList <>(); // find the kid with the most candy raw int max = candies[ 0 ]; for ( int i = 1 ; i < candies . length ; i++){ max = Math . max (candies[i], max); } for ( int i : candies){ if (i + extraCandies >= max) high . add ( true ); ...