Consider an idealized gossip protocol with no duplicate contacts. The cluster starts with one informed node. During each round, every informed node tells fanout new uninformed nodes, subject to the cluster size.
Design a GossipSpreadSimulator class:
GossipSpreadSimulator() creates a stateless simulator.int[] spread(int n, int fanout, int numRounds) returns the informed-node count after every round.
For each round, update the count as follows:
Return exactly numRounds counts. Continue returning n for later rounds after the entire cluster is informed. Use wide arithmetic before applying the cap.
Example 1:
Input:
Output:
Explanation: Each informed node contacts one new node, so the informed population doubles per round.
Example 2:
Input:
Output:
Explanation: The uncapped third-round count would be 27. Only 10 nodes exist, so the result is capped at 10.
Constraints
1 <= n <= 10^90 <= fanout <= 10^90 <= numRounds <= 100- The simulation assumes every contact reaches a new uninformed node until all
n nodes are informed. - At most
100 calls are made to spread.