Practice Maximum Score of a Node Sequence
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
scores[i] is node i value and each edges entry [a,b] is an undirected edge. Choose a sequence of exactly four different nodes with an edge between each consecutive pair. Return the greatest sum of their scores, or -1 when no such sequence exists.
Source: Maximum Score of a Node Sequence on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]
Output
24
# Example 2
Input
scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]]
Output
-1
Constraints
n == scores.length
4 <= n <= 5 * 10^4
1 <= scores[i] <= 10^8
0 <= edges.length <= 5 * 10^4
edges[i].length == 2
0 <= ai, bi <= n - 1
ai != bi
There are no duplicate edges.
Related LeetCode Problems
Practice more problems similar to Maximum Score of a Node Sequence.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.