⭐ Maximum Star Sum in a Graph 🔥
🧠 Intuition
Given a graph where each node has a value, we want to find the maximum star sum.
A star is a node with at most k neighbors contributing to its sum.
## 🧠 Intuition  
- Given a **graph** where each node has a **value**, we want to find the **maximum star sum**.  
- A **star** is a **node with at most `k` neighbors** contributing to its sum.  
- We need to **maximize** this sum by picking the `k` highest-value neighbors.

---

## 🛠️ Approach  
1. **Construct the Graph** using an **adjacency list**.  
2. **Iterate over each node**:
   - Use a **max-heap** (`priority_queue<int>`) to store **neighbor values**.
   - Extract the **top `k` max values** to maximize the **star sum**.
   - Update the **global maximum result**.
3. **Edge Case:**  
   - If **no edges exist**, return the **max node value**.

---

## ⏳ Complexity  
- **Time Complexity:**  
  - **Graph Construction:** $$O(E)$$ (where `E` is the number of edges).  
  - **Processing Each Node:** $$O(N \log N)$$ (due to `priority_queue`).  
  - **Overall:** $$O(N \log N + E)$$.  
- **Space Complexity:**  
  - $$O(N + E)$$ for storing adjacency lists.

---

## 💻 Code  
```cpp []
class Solution {
public:
    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {
        if (edges.size() == 0)
            return *(max_element(vals.begin(), vals.end()));

        int n = vals.size();
        int res = INT_MIN;
        vector<vector<int>> adj(n);

        for (auto &edge : edges) {
            adj[edge[0]].push_back(edge[1]);
            adj[edge[1]].push_back(edge[0]);
        }

        for (int i = 0; i < n; i++) {
            priority_queue<int> pq;
            for (int neighbor : adj[i])
                pq.push(vals[neighbor]);

            int currRes = vals[i];
            res = max(res, currRes);
            
            for (int t = 0; t < k && !pq.empty(); t++) {
                currRes += pq.top();
                res = max(res, currRes);
                pq.pop();
            }
        }
        return res;
    }
};
```

---

### 🚀 Key Takeaways  
✔ **Uses priority queue to efficiently extract top `k` values.**  
✔ **Handles disconnected graphs by returning max node value.**  
✔ **Efficient `O(N log N)` complexity makes it feasible for large graphs.**  

🔥 **Optimized and efficient solution for maximum star sum in graphs!** 🚀✅
['Array', 'Greedy', 'Graph', 'Sorting', 'Heap (Priority Queue)', 'C++']