Trains the technique from
LeetCode 2497Maximum Star Sum of a GraphThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A survey network has n sites numbered 0 through n - 1. Site i reports a yield of vals[i], which may be negative. edges[j] = [a, b] is a two-way cable between site a and site b.
A cluster is one site chosen as the hub, together with any set of at most k sites that share a cable with it. The hub is always part of its own cluster, and a cluster may consist of the hub alone. The yield of a cluster is the sum of the yields of its sites.
Return the largest yield any cluster can have.
Example 1
Taking site 0 as the hub and site 2 as its only spoke gives 2 + 5 = 7. Sites 0 and 2 do share a cable, and one spoke is within the allowance of two.
Example 2
Every yield is negative. A cluster of site 0 alone has yield -5, and no cluster does better.
Example 3
Site 0 as the hub gives 10, and adding either zero-yield spoke leaves the total at 10, so 10 is the largest yield.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_hub_yield(vals: list[int], edges: list[list[int]], k: int) -> int:public int bestHubYield(int[] vals, int[][] edges, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.