Skip to content

Practice Maximum Star Sum of a Graph

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2497
LeetCode Problem

Maximum Star Sum of a Graph

Problem Statement

vals[i] is node i value and edges gives undirected connections [a,b]. Choose a center and up to k distinct neighboring nodes, including the option of no neighbors. Return the largest sum of the center and chosen neighbors. Only the chosen center-neighbor edges are needed; other graph edges do not invalidate the star.

Source: Maximum Star Sum of a Graph on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
vals = [1,2,3,4,10,-10,-20], edges = [[0,1],[1,2],[1,3],[3,4],[3,5],[3,6]], k = 2
Output
16

# Example 2

Input
vals = [-5], edges = [], k = 0
Output
-5

Constraints

n == vals.length
1 <= n <= 10^5
-10^4 <= vals[i] <= 10^4
0 <= edges.length <= min(n * (n - 1) / 2, 10^5)
edges[i].length == 2
0 <= ai, bi <= n - 1
ai != bi
0 <= k <= n - 1

Related LeetCode Problems

Practice more problems similar to Maximum Star Sum of a Graph.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.