100% Best solution using C# (easy beginner friendly) 
ExplanationWe need to find the maximum number of candies that can be evenly distributed among k children. The goal is to determine the largest possible pile siz

### **Explanation**
We need to find the **maximum** number of candies that can be evenly distributed among **k** children. The goal is to determine the largest possible **pile size** each child can receive.  

#### **Intuition**
- If we fix a pile size **m**, we can check how many children can get at least **m** candies by dividing each candy pile by **m** and summing up the results.
- Since increasing **m** will reduce the number of children that can be served, we can apply **binary search** on **m** to efficiently determine the optimal pile size.

#### **Approach**
1. **Binary Search on Answer:**  
   - The **minimum pile size** (`l`) is `1` (each child gets at least one candy).  
   - The **maximum pile size** (`r`) is `max(candies)`, since we can’t have a pile size greater than the largest candy pile.  
   - We perform binary search in this range `[1, max(candies)]` to find the **largest valid pile size**.

2. **Counting Children Served:**  
   - For a given pile size **m**, compute the total number of children that can be served:  
     \[
     \sum \frac{\text{candies[i]}}{m}
     \]
   - If this count is **greater than or equal to k**, then **m** is valid, so we try a larger **m**.  
   - Otherwise, we try a smaller **m**.

3. **Binary Search Termination:**  
   - When `l > r`, the optimal pile size is `r`.

---

### **C# Code Implementation**
```csharp
using System;
using System.Linq;

public class Solution {
    public int MaximumCandies(int[] candies, long k) {
        int l = 1;
        int r = candies.Max(); // Maximum candy pile size

        while (l <= r) {
            int m = (l + r) / 2; // Mid value for binary search
            long count = 0;

            // Calculate how many children can receive at least `m` candies
            foreach (int candy in candies) {
                count += candy / m;
            }

            // If we can serve at least `k` children, try a larger pile size
            if (count >= k) {
                l = m + 1;
            } 
            // Otherwise, reduce the pile size
            else {
                r = m - 1;
            }
        }
        
        return r; // Maximum valid pile size
    }
}
```

---

### **Complexity Analysis**
- **Time Complexity:**  
  - **Binary search range:** `O(log(max(candies)))`  
  - **Iteration through `candies` per binary search step:** `O(n)`  
  - **Total complexity:** `O(n log(max(candies)))`
  
- **Space Complexity:**  
  - `O(1)`, since we only use a few integer variables.

---

### **Example Walkthrough**
#### **Example 1**
```csharp
int[] candies = {5, 8, 6};
long k = 3;
Solution sol = new Solution();
Console.WriteLine(sol.MaximumCandies(candies, k)); // Output: 5
```
##### **Explanation**
- Maximum candy pile size **5** is possible:  
  - `{5, 8, 6} → {1, 1, 1}` (each child gets **5** candies, total `3` children served)
- Trying **6** fails since only `2` children can be served (`{5,8,6} → {0,1,1}`)
- Hence, the answer is **5**.

---

### **Edge Cases Considered**
✔ **Single pile of candies**: `{10}, k = 5`  
✔ **All elements are equal**: `{4, 4, 4, 4}, k = 3`  
✔ **Large `k` where no valid split exists**  
✔ **Largest possible candy pile is less than `k`**  

# Please upvote for 5 years of good luck

['C++']