6. 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:
- The parent of server i is server floor((i-1)/2), for i ≥ 1. Here, floor(x) denotes the greatest integer less than or equal to x.
- The children of server i are the servers numbered 2i + 1* and 2i + 2*, if they exist.
- The root server (server 0) has no parent.
The root server (server 0) handles requests, which are passed down to its child servers.
- The latency cost between server j and its parent is defined as the time taken for data to travel along the edge between them. It is given by latency[j].
- The latency from the root server to any server is the sum of latencies along the path from the root to that leaf.
The 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.
Example
Suppose n = 7 and latency = [3, 1, 2, 1, 5, 4].
The given arrangement should look like this:
7. Maximum Positive Feedback
The TikTok Content creator's videos receives feedback from viewers over time, represented as a binary string, videoFeedback:
- 1 indicates positive reactions (likes, shares, or comments).
- 0 indicates negative reactions (skips or dislikes).
The creator wants to improve the video's overall positive reaction by strategically targeting a portion of the video from re-editing.
- Choose one specific segment of videoFeedback (an interval [i, j]) to leave unchanged, where i > 0 and j < videoFeedback_size.
- Outside this segment, the plan is to completely change the content—flipping negative reactions to positive (0 to 1) and positive reactions to negative (1 to 0).
The objective is to maximize the total positive feedback (1s) for the entire video after performing this operation.
Note: The operation must be performed only once.
Example
Given videoFeedback_size = 6 and videoFeedback = "100110":
The interval i = 4 to j = 5 can be selected as the unchanged segment of the video.
Flipping the bits from index 1 to 3 transforms the string from "100110" to "011110".
Next, flipping the bit at index 6 (i.e., the last bit) changes the string from "011110" to "011111".
The number of positive reactions in the output should be 5. There are no intervals that produce an optimal result greater than 5.