本帖最后由 thereggss 于 2024-11-16 22:24 编辑
5个选择2个大题,总共110分钟:
第一题:
选了第3个
第二题:
选了第1个
第三题:
选了第3个
第四题:
选了第2个
第五题:
选了第2个
第六题:
6. TikTok Reel lmpact
In the dynamic landscape of TikTok, creators are in a constant race to boost their videos' engagement and reach by leveraging new features that enhance their content.
Each creator starts with a set of mvideos represented by initialReellmpacts, which indicates the baseline popularity of each reel. For next n days, TikTok releases new trending features represented by newReellmpacts, with each feature offering an additional boost to the creator's existing reels.
On each of the next n days, the following takes place:
The creator appends the new features represented by newReellmpacts[i] (where 0 s i< n) to their current reels
Review the updated lineup, select the k-th most impactful reel based on its popularity, and add its impact value to their total impact score
For example, if k = 1, the creator selects the reel with the highest popularity; if k= 2, the creator selects the reel with the second highest popularity, and so on.
Given two integer arrays, initialReellmpacts and newReellmpacts of length m and n respectively and an integer k, The task is to calculate the creator's total impact score after incorporating all elements fromnewReellmpacts across n days.
Note: The initial impact score of the creator is considered to be the k-th highest impact value from the initial set of initialReellmpacts.
Example
m=2
initialReellmpacts =[2, 3]
n=3
newReellmpacts =[4, 5, 1]
k=2
The initial impact score of the creator is 2nd highest impact value from the initial set of initialReellmpacts =[2, 3]. Thus,impact score=2
Over the next n days the following process unfolds:
Index, newReellmpacts[i], currentreelsimpact, k-th highest, impact score
0, 4, [2, 3, 4], [2, 3, 4], 3, 2+3=5
1, 5, [2, 3, 4, 5], [2, 3, 4, 5], 4, 5+4=9
2, 1, [2,3, 4, 5,1], [1, 2, 3, 4, 5], 4, 9+4=13
Day 1: The creator appends a new reel with an impact of 4, resulting in [2, 3, 4], and selects the 2nd highest impact of 3, making impact score 2+3 =5.
Day 2: The creator appends a new reel with an impact of 5, resulting in [2, 3, 4, 5], and selects the 2nd highest impact of 4, bringing total impact score to 5 +4=9.
Day 3: The creator appends a new reel with an impact of 1, resulting in [1, 2, 3, 4, 5], and selects the 2nd highest impact of 4, making total impact score to 9 +4= 13.
Therefore the creator's total impact score after incorporating all elements from newReellimpacts across given n days is 13.
Hence return 13 as the answer.
Function Description
Complete the function getTotalImpact in the editor below.
getTotalImpact has the following parameter(s):
int initialReellmpacts[m]: The impact of initial m reels
int newReellmpacts[n]: The impact of the new n reels that appear one by one
int k: The fixed choice made by the creator, representing the position of the most impactful reel selected
Returns
long: The total impact achieved by the creator after incorporating all elements from newReellmpacts.
我的答案:
test cases 16/16
第七题:
7. Maximize Throughput
In ByteDance's vast network of data centers, millions of interconnected servers process content reguests, handle user interactions, and deliver data to users globally. Each server is part of a dynamic task execution flow, represented by an array serverTasks, where each entry in the array indicates the next server in the chain that will handle a task.
Optimizing the data pipeline requires careful management of these task handoffs. Once a task is picked up by server i, it triggers a dependency on server serverTasks[i], transferring the load there. However, this data transfer disables both servers iand serverTasks[i] from participating in any further task handoffs, as they are locked due to processing the current load. Therefore, selecting the right servers and managing the chain reactions of these task handoffs is crucial for maximizing throughput.
Each server at index i points to the next server serverTasks[i], where the task is transferred. Once this transfer occurs, both the sending server and the receiving server become unavailable for subsequent tasks. Your challenge is to select servers in such a way that maximizes the overall throughput score. The throughput score is determined by the sum of the indices of the servers where tasks are successfully handed off.
Your task is to analyze this network of server-to-server task handoffs, navigate the dependencies. and determine the maximum possible throughput score that can be achieved by optimally choosing the task handoffs.
Given the array serverTasks, calculate the maximum throughput score achievable by performing these operations in the most efficient way.
Example
n=3
serverTasks =[0, 1, 2]
We first select the server at index 0. lt points to itself (server 0), and its throughput is 0. So, the current total throughput is 0. Note that server 0 is now blocked.
Next, we select the server at index 1. lt points to itself (server 1), and its throughput is 1. So, the current total throughput becomes 0 + 1 = 1. Note that both servers 0 and 1 are now blocked.
Then, we select the server at index 2. lt points to itself (server 2), and its throughput is 2. So, the current total throughput becomes 0+1+2= 3.
All servers are now blocked.
Thus, the maximum achievable throughput score is 3.
Function Description
Complete the function calculateMaxProcessingThroughputin the editor below
calculateMaxProcessingThroughput has the following parameter(s):
senverTasks[n]: An array of integers where each element indicates the next server where the task is to be transferred.
Returns
long: The maximum throughput score achievable.
Explanation
serverTasks=[3, 0, 1, 2]
We first select the server at index 2(serverTasksl[i] = 1), which points to index 1(serverTasks[1] = 0) and its throughput is equal to 1. So, the current total throughput is 1. Note that both i= 1 and j= 2 are now blocked.
Next, we select the server at index 3(serverTasks[i]= 2), which points to index 1 but index 1 is blocked. So, the current total throughput becomes 1 + 2 = 3. Note that now i= 1, 2, 3 are now blocked.
Finally, we select the server at index 0(serverTasks[i] = 3), which points to index 3 but index 3 isblocked. So, the current total throughput becomes 1+2+3= 6.
All servers have been blocked now.
Thus, the maximum achievable throughput score is 6.
For more clarity, we show one more way of choosing indices for same sample:
serverTasks =[3, 0,1, 2]
We first select the server at index 0(serverTasks[i] = 3), which points to index 3(serverTasks[3]= 2) andits throughput is equal to 3. So, the current total throughput is 3. Note that both i= 0 and i= 3 have been blocked now.
Next, we select the server at index 2(serverTasks[i] = 1, which points to index 1 and blocks both i= 1 and i=2.
Since the throughput at index 2 is equal to 1, the total current throughput becomes 3 +1 =4.
All servers are now blocked. However, note that this achievable throughput score is 4, although it is not optimal
test case:
[2, 1, 0] 正确答案输出3
[3, 0, 1, 2] 正确答案输出6
[0, 4, 2, 1, 3] 正确答案输出9
test cases 4/16,实在跑不对,没搞出来,有思路的大佬可以分享一下
最后求大家加米,感谢! |