Equalize Server Latency
TikTok's server network is structured as a perfect binary tree with n servers, where servers are numbered from 0 to n-1.
Each server is connected to its parent with the following configuration:
i is floor((i-1)/2), for i > 1.
Here, floor(x) denotes the greatest integer less than or equal to xi are the servers numbered 2*i + 1 and 2*i + 2, if they exist0) has no parent
The root server (server 0) handles requests, which are passed down to its child servers.
i and its parent is defined as the time taken for data to travel along the edge
between them and is given by latency[i-1] for i > 1The goal is to ensure that the latency from the root to every leaf server is the same. Currently, latencies along different paths may vary. You are allowed to increase the latency of some connections but cannot decrease any latency. You have to find the minimum amount of additional latency needed to equalize the latency from the root to all leaf servers.
Complete the function minAdditionalLatency.
minAdditionalLatency has the following parameters:
int n: the number of serversint[] latency: an array of integers representing the latency costs
Returns
int: the minimum additional latency needed to equalize the latency from the root to all leaf servers
1Example 1

2Example 2
