Gossip Consensus on the Maximum Value
Problem statement
Node i starts knowing values[i]. edges describes a connected undirected network. In one synchronous round, each node replaces its known value with the maximum value known at the start of that round by itself and all of its neighbors.
Return [globalMaximum, roundsUntilEveryNodeKnowsIt].
Function
gossipMaximum(values: int[], edges: int[][]) → int[]Examples
Example 1
values = [3,9,2,5]edges = [[0,1],[1,2],[2,3]]return = [9,2]The maximum starts at node 1 and reaches node 3 after two synchronous rounds.
Constraints
1 <= values.length <= 10^5.- The graph is connected.