Kids With the Greatest Number of Candies

by raviteja gunda

HTML

There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have.

Return a boolean array result of length n, where result[i] is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.

Note that multiple kids can have the greatest number of candies.

Input: candies = [2,3,5,1,3], extraCandies = 3
Output: [true,true,true,false,true]

TypeScript

function kidsWithCandies(candies: number[], extraCandies: number): boolean[] {
    const results = [];
    const max = Math.max(...candies);

    for(const candy of candies) {
       results.push(candy + extraCandies >= max);
    }

    return results;
};


//top
function kidsWithCandies(candies: number[], extraCandies: number): boolean[] {
  const max = Math.max(...candies);
  return candies.map((candyNum) => candyNum + extraCandies >= max);
};