Tiktok Equalizing Bandwidth
TikTok Infrastructure team has n
backend servers that process real-time API requests. Each server has a current bandwidth allocation (in Mbps) in an array servers
, and the team needs to equalize the bandwidth across all servers for efficient load distribution.
Maintenance Cycles
Maintenance cycles occur in two phases, alternating every hour:
Light Upgrade
- Can only be applied on odd hours.
- Select any server and increase its bandwidth by 1 Mbps.
Heavy Upgrade
- Can only be applied on even hours.
- Select any server and increase its bandwidth by 2 Mbps.
- May skip maintenance during any hour as a valid move.
- Limit: Only one upgrade is allowed on one server in a single hour.
Objective
Given an integer array servers
of length n
, determine the minimum number of hours needed to make the bandwidth equal across all servers.
Example
n = 3
servers = [1, 2, 4]
Tiktok Video Clusters
TikTok’s playlist curation algorithm aims to identify collections of videos that meet specific quality thresholds.
Given an array videoLengths
of size n
, where each element represents the length of a video, determine how many playlists containing exactly k
videos meet the criteria that all videos in the playlist have lengths less than or equal to a given value, threshold
.
Note: A playlist is defined as any contiguous sequence of videos from the array (subarray).
Example
n = 7
videoLengths = [3, 1, 5, 6, 8, 2, 1]
k = 2
threshold = 5
The subarrays of length 2 in which all integers are less than or equal to 5 are:
[3, 1], [1, 5], [2, 1]
Hence, there are 3 subarrays that meet the given condition.
Function Description
Complete the function getPlaylistCount
in the editor below.
getPlaylistCount has the following parameters:
int videoLengths[n]: representing the lengths of videos
int k: the number of videos in a given playlist
int threshold: the maximum length of a video that is added in playlist
Returns
int: the total number of playlists that can be created
Constraints
1 ≤ n ≤ 10^5
1 ≤ videoLengths[i] ≤ 10^9
我们长期稳定承接各大科技公司如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.
