Magicsheet logo

Kids With the Greatest Number of Candies

Easy
44.3%
Updated 6/1/2025

Kids With the Greatest Number of Candies

1. What is this problem about?

The Kids With the Greatest Number of Candies interview question is a simple comparison task. You are given an array candies and an integer extraCandies. For each kid, you need to determine if giving them all the extraCandies would make them have the greatest number of candies among all the kids.

2. Why is this asked in interviews?

Companies like Meta, Amazon, and Infosys use this as an introductory "Easy" question. It tests a candidate's ability to perform a Two-Pass Array scan and handle basic logic. It evaluations whether you can identify that you must find the current maximum before making individual comparisons.

3. Algorithmic pattern used

This problem follows the Find Max and Compare pattern.

  1. Pass 1: Iterate through the array to find the current maximum number of candies any kid has.
  2. Pass 2: Iterate through the array again. For each kid ii:
    • Check if candies[i] + extraCandies >= maxCandies.
    • Store the result (true/false) in a result list.
  3. Return: The list of boolean values.

4. Example explanation

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

  1. Max candies is 5.
  2. Kid 0: 2+3=552+3=5 \geq 5 (True).
  3. Kid 1: 3+3=653+3=6 \geq 5 (True).
  4. Kid 2: 5+3=855+3=8 \geq 5 (True).
  5. Kid 3: 1+3=4<51+3=4 < 5 (False).
  6. Kid 4: 3+3=653+3=6 \geq 5 (True). Result: [true, true, true, false, true].

5. Common mistakes candidates make

  • One-Pass attempt: Trying to find the max and compare in a single pass, which is impossible because you don't know the global maximum until the end.
  • Off-by-one: Using > instead of >=.
  • Inefficient Max find: Re-calculating the max inside the second loop (O(N2)O(N^2)).

6. Interview preparation tip

Always look for the pre-requisite information. In many array problems, finding the global max, min, or sum is the necessary first step before individual elements can be evaluated. This is a basic Array interview pattern.

Similar Questions