- 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 serverfloor((i-1)/2)
, fori ≥ 1
. Here,floor(x)
denotes the greatest integer less than or equal tox
. - The children of server
i
are the servers numbered2*i + 1
and2*i + 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
i
and its parent is defined as the time taken for data to travel along the edge between them and is given bylatency[(i-1)/2]
fori ≥ 1
. - The latency from the root server to any leaf server is the sum of the 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:
- Maximum Positive Feedback
The TikTok Content creator’s videos receive 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 a video’s overall positive reception by strategically targeting a portion of the video from re-editing or improvement. Here’s the strategy:
- Choose one specific segment of the video (interval
[i, j]
) to leave unchanged, wherei > 0
andj < videoFeedback_size
. - Outside this segment, the plan is to completely change the content—flipping negative reactions to positive (
0
to1
) and positive reactions to negative (1
to0
).
The objective is to maximize the total positive feedback (1
s) 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
toj = 5
can be selected as the unchanged segment of the video. - Flipping the bits from index
1
to3
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"
.
As this string contains 5
ones, the output should be 5
. There are no intervals that produce a higher count of 1
s.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
