Could Each Child Have the Most Candies?

Quick Overview

Could Each Child Have the Most Candies?. For each child independently, imagine giving that child all extraCandies while leaving every other count unchanged.

Could Each Child Have the Most Candies?

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem For each child independently, imagine giving that child all extraCandies while leaving every other count unchanged. Return a boolean array indicating whether that child would then have a greatest count. Ties for greatest are allowed; the hypothetical gifts are separate scenarios. ```cpp class Solution { public: vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies); }; ``` ### Examples **Example 1:** ```text Input: candies = [1,4,3], extraCandies = 1 Output: [false,true,true] Explanation: The hypothetical totals2,5,4 must reach at least the original maximum4. ``` **Example 2:** ```text Input: candies = [2,2], extraCandies = 3 Output: [true,true] Explanation: Either child would have5 in that child's own scenario. ``` ### Constraints - n equals candies.length, with `2 <= n <= 100`. - `1 <= candies[i] <= 100` and `1 <= extraCandies <= 50`. ### Contract considerations Each output position describes an independent hypothetical gift. ```hint Read the boundary condition Evaluate each child's gift in a separate scenario. A tie for the greatest count qualifies. ``` ### Boundary reminders Each output position describes an independent hypothetical gift.

Overview: Could Each Child Have the Most Candies?. For each child independently, imagine giving that child all extraCandies while leaving every other count unchanged.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

For each child independently, imagine giving that child all extraCandies while leaving every other count unchanged. Return a boolean array indicating whether that child would then have a greatest count. Ties for greatest are allowed; the hypothetical gifts are separate scenarios.

class Solution {
public:
    vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies);
};

Examples

Example 1:

Input: candies = [1,4,3], extraCandies = 1
Output: [false,true,true]
Explanation: The hypothetical totals2,5,4 must reach at least the original maximum4.

Example 2:

Input: candies = [2,2], extraCandies = 3
Output: [true,true]
Explanation: Either child would have5 in that child's own scenario.

Constraints

  • n equals candies.length, with 2 <= n <= 100 .
  • 1 <= candies[i] <= 100 and 1 <= extraCandies <= 50 .

Contract considerations

Each output position describes an independent hypothetical gift.

Boundary reminders

Each output position describes an independent hypothetical gift.