Skip to content

Practice Node With Highest Edge Score

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

Medium#2374
LeetCode Problem

Node With Highest Edge Score

Problem Statement

You are given a directed graph with n nodes labeled from 0 to n - 1, where each node has exactly one outgoing edge. The graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicates that there is a directed edge from node i to node edges[i]. The edge score of a node i is defined as the sum of the labels of all the nodes that have an edge pointing to i. Return the node with the highest edge score. If multiple nodes have the same edge score, return the node with the smallest index.

Source: Node With Highest Edge Score on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
edges = [1,0,0,0,0,7,7,5]
Output
7

# Example 2

Input
edges = [2,0,0,2]
Output
0

Constraints

n == edges.length
2 <= n <= 10^5
0 <= edges[i] < n
edges[i] != i

Related LeetCode Problems

Practice more problems similar to Node With Highest Edge Score.

Review your practice with PhantomCodeAI

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