The Maximum Star Sum of a Graph coding problem asks you to find the maximum possible "star sum" of a node in a graph. A star graph consists of a center node and at most k of its neighbors. The "star sum" is the sum of the value of the center node plus the values of its chosen neighbors. You want to pick the neighbors that have the highest positive values to maximize the sum.
Amazon and Google ask this to test a candidate's understanding of graph representation (adjacency lists) and greedy selection. It requires you to iterate through each node, treat it as a potential center, and quickly find its best neighbors. It evaluates your ability to handle basic graph data structures and sorting or priority queues efficiently.
This problem follows the Graph, Sorting, and Greedy interview pattern. First, build an adjacency list where each node stores the values of its neighbors. Then, for each node:
k neighbors, but only if their values are positive (adding a negative value would decrease the star sum).Node 1 (val 10) connected to: Node 2 (val 5), Node 3 (val -2), Node 4 (val 8). k = 2.
A common error is including neighbors with negative values, which reduces the total sum. Another mistake is forgetting that the "center" node's value can be negative, and the star sum might just be the value of a single node if all neighbors are negative or k=0. Candidates also sometimes fail to efficiently sort neighbors, which is fine if k is small but can be optimized with a Max-Heap if needed.
In "Graph, Greedy interview pattern" problems, the choice for one node often doesn't affect another. This allows you to solve for each node independently. Always clarify if the neighbors' values are stored on the nodes or the edges, as this changes the adjacency list implementation.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximum Subsequence Score | Medium | Solve | |
| Maximum Total Importance of Roads | Medium | Solve | |
| Maximum Number of Events That Can Be Attended | Medium | Solve | |
| Mice and Cheese | Medium | Solve | |
| Minimum Amount of Time to Fill Cups | Easy | Solve |