1431. Kids with Greatest Number of Candies
Difficulty: EASY
Problem description can be found here
Approach
Section titled “Approach”One learning point or “recap” for me was to use Math.max(...numArr) to easily find the max number in an array of numbers
in JavaScript.
Solution
Section titled “Solution”function kidsWithCandies(candies: number[], extraCandies: number): boolean[] { const currentMax = Math.max(...candies);
const output: boolean[] = []; for (const candy of candies) { if (candy + extraCandies >= currentMax) { output.push(true); } else { output.push(false); } }
return output;}