FastPrepMaximize Throughput (AMS)
Problems/Maximize Throughput (AMS)

Maximize Throughput (AMS)

TikTok logoTikTok● MediumNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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

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.

Function

calculateMaxProcessingThroughput(serverTasks: int[]) → long

Examples

Example 1

serverTasks = [0, 1, 2]return = 3

First, select the server at index 0. It points to itself, so its throughput is 0 and server 0 becomes unavailable.

Next, select the server at index 1. It also points to itself, so the total becomes 0 + 1 = 1 and server 1 becomes unavailable.

Finally, select the server at index 2. The total becomes 0 + 1 + 2 = 3.

Example 2

serverTasks = [2, 1, 0]return = 3

Example 3

serverTasks = [3, 0, 1, 2]return = 4

Select servers 1 and 3. The first handoff disables servers 1 and 0, and the second disables servers 3 and 2. All four servers are then unavailable, and the total throughput score is 1 + 3 = 4.

Constraints

  • 1 ≤ n ≤ 200000
  • 0 ≤ serverTasks[i] < n

More TikTok Online Assessment questions

  • Center of the Largest Perfect X-ShapeOA · Seen Nov 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Nov 2026
  • Count Suffix Word PairsOA · Seen Nov 2026
  • Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
  • Count Subarrays with at Least K Equal-Fruit PairsOA · Seen Oct 2026
  • Shell Command Counts with History ReferencesOA · Seen Oct 2026
  • Product Minus Sum of DigitsOA · Seen Aug 2026
  • Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
  • Find All Local PeaksOA · Seen Aug 2026
  • Count Case-Insensitive TripletsOA · Seen Aug 2026

Similar questions at other companies

  • Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA
  • Maximum Sum of a K-StarMicrosoft · OAMicrosoft interview questions
  • Optimal TransferSnowflake · OASnowflake interview questions
  • Maximum K-Star SumC3.ai · OAC3.ai interview questions
  • Maximum K-Star SumAkuna Capital · OAAkuna Capital interview questions
  • Doctor Appointment Slot AssignmentDRW · OADRW interview questions
  • Min Cost to Connect All PointsNutanix · OANutanix interview questions
  • Google Drive Folder Hierarchy SyncGoogle · OAGoogle interview questions
  • Minimum Cost to Supply Water with Wells and PipesInfosys · OAInfosys interview questions
  • Optimal TransferVisa · OAVisa interview questions

TikTok interview experiences

  • TikTok AI Infra Intern LLM Round 2: 1 Experience
  • TikTok AI Infra Intern DeepSpeed Round: 1 Experience
  • TikTok AI Infra Intern Kernel Round: 1 Experience
  • TikTok AI Infra Intern Interviews, 3 Rounds: 1 Experience
  • TikTok AI Infra Intern Interview Timeline: 1 Experience
  • TikTok AI Infra Intern Onsite Round 2: 1 Experience
All TikTok interview questionsSee TikTok hiring insights
Saved
class Solution {
    public long calculateMaxProcessingThroughput(int[] serverTasks) {
      // write your code here
    }

}
Checking account…