Practice/Amazon/Leetcode 2374. Node With Highest Edge Score
CodingOptional
You are given a directed graph represented by an array edges where each node has exactly one outgoing edge. The graph contains n nodes labeled from 0 to n-1, where n is the length of the edges array.
For node i, there is a directed edge pointing to node edges[i].
Each node has an influence score defined as the sum of all node labels that have edges pointing to it. In other words, if nodes a, b, and c all point to node x, then node x's influence score is a + b + c.
Your task is to find the node with the highest influence score. If multiple nodes share the highest score, return the node with the smallest label.
n == edges.length1 <= n <= 100,0000 <= edges[i] < nExample 1:
` Input: edges = [1, 2, 0, 2] Output: 2
Explanation: Node 0 points to node 1 Node 1 points to node 2 Node 2 points to node 0 Node 3 points to node 2
Influence scores:
Node 2 has the highest score of 4. `
Example 2:
` Input: edges = [2, 2, 1, 1] Output: 1
Explanation: Influence scores:
Node 1 has the highest score of 5. `
Example 3:
` Input: edges = [0] Output: 0
Explanation: Only one node exists, pointing to itself with score 0. `