FastPrepGossip Consensus on the Maximum Value

Gossip Consensus on the Maximum Value

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] gossipMaximum(int[] values, int[][] edges) {
  // Write your code here.
}
values[3,9,2,5]
edges[[0,1],[1,2],[2,3]]
expected[9,2]
Checking account…