Equalize Server Latency
Learn this problemProblem statement
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.
Function
minAdditionalLatency(n: int, latency: int[]) → int
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
Examples
Example 1
n = 7latency = [3, 1, 2, 1, 5, 4]return = 3
Example 2
n = 3latency = [10, 5]return = 5
More Tiktok problems
- Can Reach the Exit with TeleportsOA · Seen Jul 2026
- Check Monotonic TriplesOA · Seen Jul 2026
- Shift Every K-th ConsonantOA · Seen Jul 2026
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Sort Matrix BordersOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Validate 3x3 Digit WindowsOA · Seen Jul 2026