 Beats 100% 🚀🔥| Optimized Binary Search Solution for Maximum Candies 🍬 
Intuition 💡🤔The goal is to distribute candies 🍬 among k children 👦👧 such that each child gets the maximum possible number of candies.Instead of checking all pos
# Intuition 💡🤔  
The goal is to distribute candies 🍬 among `k` children 👦👧 such that each child gets the **maximum possible number of candies**.  

Instead of checking all possible values (which is slow ❌), we recognize that the **maximum possible candies per child** lie between `1` and `sum(candies) / k`. Using **binary search 🔍**, we efficiently find this maximum value without unnecessary calculations.  

---

# Approach 🚀⚡  
We use **binary search** 🏹 to determine the **largest possible** number of candies 🍬 that can be evenly distributed among `k` children.  

---

### **Steps 📝**  
1️⃣ **Compute the total number of candies (`sum`)** and **find the smallest candy pile (`mini`)**.  

2️⃣ **Edge Case Check 🔴:**  
   - If `sum < k`, it's impossible to give at least one candy 🍬 to each child 👦 → return `0`.  

3️⃣ **Binary Search Setup 📏:**  
   - `low = 1` (minimum possible candies per child)  
   - `high = sum / k` (maximum possible candies per child)  

4️⃣ **Binary Search Execution 🔍:**  
   - Pick `mid` as the potential max candies per child.  
   - Use `isit()` function ✅ to check if it's possible to distribute at least `mid` candies per child.  
   - If **yes** 🎉 → Try increasing `mid` by moving `low` up ⬆️.  
   - If **no** ❌ → Decrease `mid` by moving `high` down ⬇️.  

5️⃣ **Return `ans` 🎯**, which stores the max candies per child.  

---
# Complexity ⏳⚙️  

| Complexity Type   | Value       | Explanation 📖 |
|------------------|------------|----------------|
| **Time Complexity ⏱️**  | `O( log (sum/k) )`  | Binary search runs in `O( log (sum/k) )`, and each check runs in `O(n)`. |
| **Space Complexity 📦** | `O(1)`  | Only a few extra variables are used. ✅ |

---

# Code 💻🔢  
```cpp
class Solution {
public:
    bool isit(vector<int>& candies, long long k, long long part) {
        long long count = 0;
        for (int &i : candies) {
            count = count + (i / part);
        }
        return count >= k;
    }

    long long maximumCandies(vector<int>& candies, long long k) {
        long long sum = 0;
        int mini = INT_MAX;
        for (int &i : candies) {
            sum += i;
            mini = min(mini, i);
        }

        if (sum < k) return 0;

        long long low = 1, high = sum / k, ans = 0;
        while (low <= high) {
            long long mid = low + (high - low) / 2;
            if (isit(candies, k, mid)) {
                ans = mid;
                low = mid + 1;
            } 
            else {
                high = mid - 1;
            }
        }
        return ans;
    }
};
```
['Array', 'Binary Search', 'C++']