---
# System prepended metadata

title: 1431. Kids With the Greatest Number of Candies
tags: [C++, LeetCode-Easy]

---

# 1431. Kids With the Greatest Number of Candies
Difficulty: Easy

## Solution

```cpp=
/**
*** Author: R-CO
*** E-mail: daniel1820kobe@gmail.com
*** Date: 2020-10-24
**/
#include <algorithm>
#include <cstdlib>
#include <vector>
using std::vector;

class Solution {
 public:
  vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
    int max_candies = *std::max_element(candies.begin(), candies.end());

    vector<bool> output(candies.size(), false);
    auto it = output.begin();
    for (auto kid : candies) {
      if (kid + extraCandies >= max_candies) {
        *it = true;
      }

      ++it;
    }

    return output;
  }
};

int main(int argc, char* argv[]) { return EXIT_SUCCESS; }

```

## Result

Success
Details 
Runtime: 4 ms, faster than 83.14% of C++ online submissions for Kids With the Greatest Number of Candies.
Memory Usage: 9.3 MB, less than 100.00% of C++ online submissions for Kids With the Greatest Number of Candies.

###### tags: `LeetCode-Easy` `C++`
