In the fierce tech job market, TikTok's recruitment draws much attention. As a global short-video social platform, it lures countless job seekers with innovation and rapid growth, and the OA is often the key step that decides whether you advance to interviews and get closer to an offer. This piece fully breaks down three high-frequency business-scenario questions—none of them obscure, but each hides an edge case that's easy to trip on.
1. Three-Question Overview
| Q | Scenario | Focus |
|---|---|---|
| Q1 | Highest average likes | Zero-division handling + smallest-ID tiebreak |
| Q2 | Tag dedup and sort | String split + set + lexicographic order |
| Q3 | Max concurrent live streams | Sweep line / difference array |
2. Question 1: Highest Average Likes
Problem
Given a 2D array user_data where each element is [userID, videos, total likes], find the user with the highest average likes (average = total likes / videos; if videos is 0, the average is 0). If multiple users tie for highest, return the smallest userID.
Example: [[1, 5, 100], [2, 3, 75], [3, 0, 0]] → output 2 (averages 20 / 25 / 0).
Approach
Iterate directly, minding two traps: zero division (treat average as 0 when videos is 0, don't actually divide) and smallest-ID tiebreak. To avoid float errors, compare with cross-multiplication rather than division:
def highest_avg_likes(user_data: list[list[int]]) -> int:
best_id = -1
best_num, best_den = -1, 1 # represent the current best average as best_num/best_den
for uid, videos, likes in user_data:
num, den = (likes, videos) if videos > 0 else (0, 1) # zero division -> average 0
# compare num/den with best_num/best_den via cross-multiplication (no floats)
if num * best_den > best_num * den or \
(num * best_den == best_num * den and (best_id == -1 or uid < best_id)):
best_num, best_den, best_id = num, den, uid
return best_id
Complexity O(n). Cross-multiplication is the key trick—it completely sidesteps float-comparison precision issues.
3. Question 2: Tag Dedup and Sort
Problem
A string represents a user's interest-tag set, tags separated by commas (e.g., "Food,Travel,Music"). Implement a function that dedups and sorts lexicographically, returning the new tag string.
Example: "Music,Food,Travel,Music" → "Food,Travel,Music".
Approach
Split → set to dedup → sort → join—almost a one-liner, but mind edges like empty strings and leading/trailing/extra commas:
def normalize_tags(tags: str) -> str:
parts = [t for t in tags.split(",") if t] # filter empties, handle extra commas
return ",".join(sorted(set(parts)))
Complexity O(k log k), k being the tag count. Trap: for input like "a,,b," with empty segments, the if t filter prevents emitting an empty tag.
4. Question 3: Max Concurrent Live Streams
Problem
A series of live-stream periods, each [start, end] (integer minutes), stored in a 2D array live_streams. Find the maximum number of streams happening simultaneously.
Example: [[10, 20], [15, 25], [20, 30]] → output 2 (two overlap during minutes 15-20).
Approach
Classic sweep line / difference array: split each interval into a "start +1" and an "end -1" event, sort by time, sweep while tracking the current concurrency and its max. Mind the endpoint—if a stream is still "live" at its end time t, the end event should be processed after a same-time start (here we use half-open semantics, so end means leaving):
def max_concurrent(live_streams: list[list[int]]) -> int:
events = []
for start, end in live_streams:
events.append((start, 1)) # start: +1
events.append((end, -1)) # end: -1
# at the same time, process end (-1) before start (+1): half-open, end means leaving
events.sort(key=lambda e: (e[0], e[1]))
cur = best = 0
for _, delta in events:
cur += delta
best = max(best, cur)
return best
Complexity O(n log n). Trap: the same-time event order decides the boundary semantics—if "end at 20" and "start at 20" count as overlapping, process +1 first. Always align with the problem statement / sample before fixing the sort key.
5. Summary
These three TikTok OA questions are all basics wrapped in business context: Q1 tests zero division + tie tiebreak (cross-multiply to avoid floats), Q2 tests string-cleaning edges (empty-segment filtering), Q3 tests the sweep line's same-time event order. The problems aren't hard, but small mistakes are the deadliest—accuracy and boundary handling are the key to AC.
FAQ
Q1: Are these three TikTok OA questions hard?
No—they're basics wrapped in business context. The real focus is edges: zero division, smallest-ID tiebreak, empty tag segments, and the sweep line's same-time event order. Small mistakes lose the most points.
Q2: Why use cross-multiplication for average likes?
To avoid float precision issues. To compare a/b with c/d, compare ad with cb—all integer arithmetic, accurate and fast—then tiebreak by smallest ID.
Q3: How do I handle endpoints for max concurrent streams?
Sweep line / difference array: start +1, end -1, sort by time, sweep for the max. The key is same-time event order—half-open processes end first; if the end time counts as overlapping, process start first. Align semantics with the sample first.
Q4: How should I prepare for the TikTok OA?
Practice edge awareness on business problems (zero division, empty input, endpoint semantics) and sweep-line / hash / sorting fundamentals. For timed mock practice on these three questions, send the job JD so we can predict the question types and build a plan.
Preparing for the TikTok OA?
The TikTok OA is mostly basics wrapped in business context, testing accuracy + boundary handling. oavoservice offers full TikTok mock support: timed business-problem simulations, sweep-line / string / hash edge-case polishing, and OA pacing practice, with question-type prediction tailored to your role. Coaches know the TikTok OA scoring logic.
Add WeChat Coding0201 now to get TikTok questions and mock practice.
Contact
- WeChat: Coding0201
- Email: [email protected]
- Telegram: @OAVOProxy