This TikTok SDE NG loop had three rounds and ran hardcore overall. The first two were pure coding, two algorithm problems each, with tight time, weighting clarity of thinking and code completeness; the problems are mid-to-high frequency algorithms that demand sensitivity to complexity and edge cases. The third was an HM round, a resume deep dive focused on infra background and system-design thinking. Here is the round-by-round debrief.
1. Round 1 Coding
Q1: Sortable With At Most One Change
Problem: Allowing at most one element modification, can the array become non-decreasing?
Scan left to right and find the first position i violating non-decreasing order (nums[i] < nums[i-1]). There are two fixes: lower nums[i-1] down to nums[i], or raise nums[i] up to nums[i-1]. Which one depends on nums[i-2]:
def check_possibility(nums) -> bool:
changed = False
for i in range(1, len(nums)):
if nums[i] < nums[i - 1]:
if changed: # already changed once, second violation -> fail
return False
changed = True
# prefer lowering nums[i-1] to nums[i] (keeps earlier order intact)
if i >= 2 and nums[i - 2] > nums[i]:
nums[i] = nums[i - 1] # can only raise nums[i]
else:
nums[i - 1] = nums[i]
return True
Time O(n), space O(1). The key is the greedy choice of which one to change — don't blindly change the latter element.
Q2: Tree Node With Minimum Average Distance
Problem: Find the node with the minimum average distance to all other nodes; each edge counts as 1; require O(n).
This is the classic rerooting DP: one DFS computes the distance sum sum0 from the root to all nodes plus each subtree's size; a second DFS reroots, deriving each child's answer from its parent: ans[child] = ans[parent] + (n - 2*size[child]). The node with the minimum distance sum is the answer.
def min_avg_distance(n, edges):
g = [[] for _ in range(n)]
for u, v in edges:
g[u].append(v); g[v].append(u)
size = [1] * n
ans = [0] * n
def dfs1(u, p, depth):
ans[0] += depth
for w in g[u]:
if w != p:
dfs1(w, u, depth + 1)
size[u] += size[w]
def dfs2(u, p):
for w in g[u]:
if w != p:
ans[w] = ans[u] + n - 2 * size[w]
dfs2(w, u)
dfs1(0, -1, 0)
dfs2(0, -1)
return ans.index(min(ans))
Two DFS passes total O(n), avoiding the O(n²) of a separate BFS per node.
2. Round 2 Coding
The interviewer opened with 2 minutes of chat (how you optimized database query performance in a recent project), then went straight to coding.
Q1: Nested Integer List Iterator
Problem: Given a nested integer list (each element is an integer or a nested list), implement an iterator that traverses all integers in order; define your own data structure and implement next() and hasNext().
Use a stack, pushing elements in reverse; in hasNext() keep unwrapping lists until the top is an integer:
class NestedIterator:
def __init__(self, nestedList):
# push in reverse so the stack top is always the next element
self.stack = nestedList[::-1]
def next(self) -> int:
# hasNext() guarantees the top is an integer, so just pop
return self.stack.pop()
def hasNext(self) -> bool:
while self.stack:
top = self.stack[-1]
if isinstance(top, int):
return True
# top is a list: pop it and push its contents back in reverse
self.stack.extend(self.stack.pop()[::-1])
return False
The interviewer probed "why is next() amortized O(1)": each element is pushed and popped at most once, so total work is linear in the element count. Remember to cover "empty nested list" and "deep nesting" cases.
Q2: Group Anagrams (Beating Sorting)
Problem: Group anagrams, required to beat O(nk log k) (k is the max string length).
The usual solution sorts each string as the key (O(k log k)), but the interviewer wanted it optimized. Use a length-26 count array turned into a tuple key, making each string O(k):
from collections import defaultdict
def group_anagrams(strs):
groups = defaultdict(list)
for s in strs:
count = [0] * 26 # "aab..." -> [2,1,0,...]
for ch in s:
count[ord(ch) - ord('a')] += 1
groups[tuple(count)].append(s) # tuple is hashable, use as key
return list(groups.values())
When the interviewer hinted "can you use a prime-product key," you can add: a prime product can overflow, so the count array is safer and fits production better. Total complexity O(nk).
3. Round 3 HM
Entirely resume-driven, with more weight on communication and growth. Self-introduction first, then questions on selected projects, focused on:
- The most challenging project (infra / system-design choices and delivery).
- How you collaborate with teammates.
- How you handle unexpected situations — share an internship story: what caused a failure, how you finally resolved it and prevented recurrence; your answer should "land," with the technical details right.
This round usually has no coding; it's "normal conversation" style, judging fit from how you express yourself.
4. Summary
TikTok SDE NG, three rounds: the first two are pure coding testing clear thinking + complete code + edge sensitivity (array greedy, rerooting DP, stack iterator, count key), the third HM tests communication and growth. The difficulty is less any single problem than doing two problems back-to-back at pace while still explaining complexity.
FAQ
Q1: How many rounds for TikTok SDE NG?
Three: the first two are pure coding (two problems each, tight time), the third is an HM resume deep dive plus infra/system design and behavioral questions.
Q2: Why not sort for group anagrams?
A sort key is O(k log k), and the interviewer wanted better. A length-26 count array turned into a tuple key is O(k) per string, O(nk) total, and avoids prime-product overflow risk.
Q3: How to answer the nested iterator steadily?
Push in reverse onto a stack, have hasNext() unwrap lists until the top is an integer, and next() just pops. Be able to explain "each element is pushed/popped at most once" => amortized O(1), and cover empty lists and deep nesting.
Q4: How to handle the back-to-back pace?
Clarify the input format before coding, cover edge cases as you write, and narrate complexity proactively. For timed practice on TikTok's fast coding rounds or real-time VO live support / VO interview assist, send the job description so we can predict the question types first.
Preparing for a TikTok interview?
oavoservice offers full-loop TikTok SDE practice: timed back-to-back two-problem mocks, drills on high-frequency patterns (rerooting DP / stack iterator / count key), and HM resume deep dives and infra system-design Q&A, plus real-time VO live support / VO interview assist. Coaches include senior engineers from top companies who know TikTok's "clear thinking + complete code" grading style.
Add WeChat Coding0201 now to get TikTok real questions and practice.
Contact
- WeChat: Coding0201
- Email: [email protected]
- Telegram: @OAVOProxy