TikTok logo

TikTok Hard Interview Questions

6 hard-level practice questions for TikTok technical interviews

TikTok software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. [CodeSignal] Synchronized Pipeline Delays


Category: Binary tree coding problem
A hierarchical data pipeline consists of n broadcast stages, numbered 1 to n, arranged in a perfect binary tree rooted at stage 0. Each stage...
Input: Binary tree
Output: Computed result
Want to practise this one?
Create a free account to open the full question and practise TikTok questions with AI.
Sign up free
coding Hard Verified Question #2

2. Dual Extremes Queue


Category: Queue-based coding problem
Design a StreamBuffer class that buffers a stream of integer latency samples in FIFO order and supports O(1) access to both the minimum and maximum...
Input: Integer(s)
Output: Integer
coding Hard Verified Question #3

3. Spread Avoidance Escape


Category: Grid/matrix coding problem
You are navigating a facility grid to escape from spreading contamination. The grid contains: - 'S' - your starting position - 'C' - the...
Input: 2D grid
Output: Integer
coding Hard Verified Question #4

4. Tiered Order Pricing


Category: String coding problem
A warehouse fulfillment system batches orders to minimize shipping costs. Orders for the same SKU that are placed within 5 minutes (300,000 ms) of...
Input: String
Output: Integer
coding Hard graph #1

1. [Graph] — Find the largest stage-category count along a dependency path


Background
TikTok video publishing involves processing stages such as transcoding, moderation, and metadata extraction. Model a processing workflow as a directed dependency graph; counting repeated stage categories along a dependency path can help engineers understand how heavily that path relies on one kind of processing.
Problem statement
You are given a string categories of length n and a list of directed edges dependencies. Nodes are numbered from 0 to n - 1, and categories[i] is the lowercase English letter identifying node i's processing category. Each edge [u, v] means that stage u must precede stage v.
A valid path is a nonempty sequence of nodes connected by directed edges. Its category value is the largest number of occurrences of any single category along that path. For example, a path with categories "abaca" has category value 3, because category a occurs three times.
Return the maximum category value over all valid paths. If the graph contains any directed cycle, return -1, even if that cycle is in a disconnected component. A cycle makes the dependency configuration invalid. Paths may begin and end at any nodes; a single node is a valid path.
Function or class signature
  • largest_category_value(categories: str, dependencies: list[list[int]]) -> int


Example 1:
Input:
{"categories":"abaca","dependencies":[[0,1],[0,2],[2,3],[3,4]]}

Output:
3

Explanation: The path 0 → 2 → 3 → 4 has categories "aaca". Category a appears three times, and no path contains more occurrences of any category.
Example 2:
Input:
{"categories":"a","dependencies":[[0,0]]}

Output:
-1

Explanation: Node 0 depends on itself, so the graph contains a directed cycle.
Constraints:
  • 1 <= n <= 100000.

  • categories contains exactly n lowercase English letters.

  • 0 <= len(dependencies) <= 100000.

  • Each dependency contains two integer node IDs in [0, n - 1].

  • Dependency pairs are distinct; self-loops are allowed.

  • The graph may be disconnected.


Follow-up:
For an acyclic graph, also return a category and a concrete path achieving the maximum value. If multiple categories qualify, choose the lexicographically smallest category; any maximizing path for that category is acceptable. Can you preserve the original asymptotic time and space bounds?
Want to practise this one?
Create a free account to open the full question and practise TikTok questions with AI.
Sign up free
coding Hard graph #2

2. Graph — Finding Influencer Networks

Background: With the growth of user-generated content, TikTok needs to identify and analyze influencer groups to improve marketing strategies. Understanding how users are connected through likes and follows can help in targeted advertising and trend forecasting.
Problem statement: Given a directed graph represented by an adjacency list, where each node represents a user and a directed edge from user A to user B means that user A follows user B, write a function to find all strongly connected components (SCCs) in the graph. An SCC is a subgraph where every vertex can be reached from every other vertex. Implement the function find_scc(graph: List[List[int]]) -> List[List[int]] that returns a list of lists, where each inner list is a component.
Function/class signature:
  • def find_scc(graph: List[List[int]]) -> List[List[int]]:

Example 1:
  • Input: graph = [[1], [2], [0], [4], [5], [4]]

  • Output: [[0, 1, 2], [4, 5]]

  • Explanation: The nodes 0, 1, 2 form one SCC and nodes 4, 5 form another since 4 follows 5.

Example 2:
  • Input: graph = [[1], [], [3], [2]]

  • Output: [[0, 1], [2, 3]]

  • Explanation: Node 0 connects to 1, forming an SCC. Nodes 2 and 3 form another because each can reach the other.

Constraints:
  • 1 <= graph.length <= 1000

  • 0 <= graph[i].length <= graph.length

  • Each node identifier is within the range of the list index.

Start practicing TikTok questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free