Skip to main content
Back to problems
Leetcode
Easy
Arrays
Greedy
Kids With The Greatest Number Of Candies

Determine which kids can end up with the greatest number of candies after receiving extra candies.

Acceptance 0%
Problem Statement

Problem

You are given an array candies, where candies[i] is the number of candies the ii-th kid has, and an integer extraCandies.

For each kid, decide whether that kid could have the greatest number of candies among all kids after receiving all of the extra candies. The extra candies can be given entirely to any one kid.

Return a list of boolean values where the ii-th value is true if the ii-th kid can have the greatest number of candies after receiving extraCandies, otherwise false.

A kid is considered to have the greatest number of candies if their candy count is at least as large as every other kid's candy count.

Input Format

  • candies: an array of integers
  • extraCandies: an integer

The input represents one test case.

Output Format

  • Return a boolean array of the same length as candies.
  • Each entry indicates whether that kid can reach the maximum candy count after receiving all extra candies.

Constraints

  • The array contains at least one kid.
  • Candy counts and extra candies are non-negative integers.
  • Typical solution should run in linear time.
Examples
Sample cases returned by the problem API.

Example 1

Input

candies = [2,3,5,1,3], extraCandies = 3

Output

[true,true,true,false,true]

Explanation

If a kid receives 3 extra candies, their final count becomes [5,6,8,4,6]. Kids 0, 1, 2, and 4 can reach at least the maximum count of the original group.

Example 2

Input

candies = [4,2,1,1,2], extraCandies = 1

Output

[true,false,false,false,false]

Explanation

The maximum current count is 4. Only the first kid can still have the greatest number after receiving 1 extra candy.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.