Round 1
Questions:
Question
In the dynamic landscape of TikTok, creators are in a constant race to boost their videos' engagement by leveraging new features that enhance their content.
Each creator starts with a set of m videos, represented by initialReelImpacts, which indicates the baseline popularity of each reel. For the next n days, TikTok releases new trending features, represented by newReelImpacts, with each feature offering an additional boost to the creator's existing reels.
PROCESS FOR EACH DAY:
- The creator appends the new feature from newReelImpacts[i] (where 0 ≤ i < n) to their current reels.
- The updated lineup of reels is reviewed, and the k-th most impactful reel is selected based on its popularity.
- The impact value of this reel is added to the total impact score.
NOTE:
- The initial impact score of the creator is the k-th highest impact value from the initial set of initialReelImpacts.
EXAMPLE INPUT:
m = 2 initialReelImpacts = [2, 3] n = 3 newReelImpacts = [4, 5, 1] k = 2
EXPLANATION:
- The initial impact score is the 2nd highest value in initialReelImpacts = [2, 3].
- Impact score = 2
- Over the next n days:
- Day 1: Append 4. Current reels: [2, 3, 4]. The 2nd highest impact is 3.
- Impact score = 2 + 3 = 5
- Day 2: Append 5. Current reels: [2, 3, 4, 5]. The 2nd highest impact is 4.
- Impact score = 5 + 4 = 9
- Day 3: Append 1. Current reels: [1, 2, 3, 4, 5]. The 2nd highest impact is 4.
- Impact score = 9 + 4 = 13
- Day 1: Append 4. Current reels: [2, 3, 4]. The 2nd highest impact is 3.
OUTPUT: Total Impact Score = 13
FUNCTION DESCRIPTION: Complete the function getTotalImpact in the editor below.
PARAMETERS:
- int initialReelImpacts[m]: The impact of initial m reels.
- int newReelImpacts[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 newReelImpacts.
EXAMPLE INPUT/OUTPUT: EXAMPLE 1: Input:
m = 2 initialReelImpacts = [2, 3] n = 3 newReelImpacts = [4, 5, 1] k = 2
Output:
13
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.
Round 2
Questions:
Question
In ByteDance's vast network of data centers, millions of interconnected servers process content requests, 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.
PROBLEM DESCRIPTION: 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 i and 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.
TASK: 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.
INPUT: Given the array serverTasks, calculate the maximum throughput score achievable by performing these operations in the most efficient way.
EXAMPLE INPUT:
n = 3 serverTasks = [0, 1, 2]
EXPLANATION:
- We first select the server at index 0. It 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. It 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. It 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.
OUTPUT:
3
FUNCTION DESCRIPTION: Complete the function calculateMaxProcessingThroughput.
FUNCTION SIGNATURE: calculateMaxProcessingThroughput(serverTasks)
PARAMETERS:
- serverTasks[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.
CONSTRAINTS: 1 ≤ n ≤ 200000 0 ≤ serverTasks[i] < n
SAMPLE INPUT AND OUTPUT: SAMPLE INPUT 0:
3 serverTasks = [2, 1, 0]
SAMPLE OUTPUT 0:
3
SAMPLE INPUT 1:
4 serverTasks = [3, 0, 1, 2]
SAMPLE OUTPUT 1:
6
EXPLANATION FOR INPUT 1: The sequence [3, 0, 1, 2] allows for a total throughput score of 6.
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.