TikTok’s three-quarters of an acre of land | TikTok 26 NG real question analysis and interview process

1,430 Views

Up to date TikTok The interview is here, let’s take a look at this wave of real process sharing~ (Tiktok One-third of an Acre has the same rhythm). There were three rounds of interviews on TikTok this time, and the overall interview was hard-core. The first two rounds are purely coding. Each round has two algorithm questions. The time is tight. The focus of the examination is on the clarity of ideas and code integrity. The question types are mainly based on medium and high-frequency algorithms and need to be sensitive to complexity and boundary conditions.
The third round is the HM interview. We first dig into the project experience from the resume and focus on infra-related background, such as system design ideas, technology selection and actual implementation. The Behavior part mainly revolves around a core project. Follow up asks about the difficulties encountered in the project and how you solved them. The final coding question is a DP-oriented question. The overall difficulty is not low, but it is quite consistent with TikTok’s actual employment style.

Tiktok SDE NG Round 1

Coding 1: Modify elements to determine whether the array is in order

Whether the array is sorted under conditions that allow modification of at most one element of the array.
Consider traversing the array from front to back, you will encounter the element nums[i] that does not meet the ordering conditions, that is, nums[i] < nums[i-1]. If i is size-1 and it is the last element, or the array is all sorted, return true directly. Otherwise, the size of nums[i+1] should be considered:

  • If nums[i+1] >= nums[i-1], such as 3 > 2 in the array 0, 1, 2, [1], 3..., then i+1 and the elements before it meet the condition of the question, and if the following elements are ordered, true will be returned;
  • Otherwise, if 3 < 4 in the array 0, 1, 4, [1], 3..., then change nums[i-1] to nums[i], and then traverse the array starting from i-2 to determine whether it is in order.

Time complexity O(n), space complexity O(1)

Ideas

  1. Traverse the array and find the first position i that violates non-decreasing order (i.e. nums[i] < nums[i-1]).
  2. If i has traversed to the end of the array or the penultimate element, it means that at most one element violates the order. You can fix it by modifying this element and return directly.True.
  3. Check if the array can be repaired by modifying nums[i-1] or nums[i].
  4. Starting from position i, continue to traverse the array backwards and check whether all elements satisfy non-decreasing order. If any out-of-order elements are found, false is returned.
  5. Returns true if the entire array satisfies non-decreasing order.

Coding 2: The node with the smallest distance

Find the node with the smallest average distance to other nodes in the tree. An edge distance is counted as 1, and the required time complexity is O(n). Reference

Ideas

  1. First, define a flag variable visited to mark whether the target node p has been found. The initial value is false.
  2. Define an empty stack stack to store the node values ​​on the path from the root node to the target node p.
  3. Define a function getDisToPar that receives three parameters: the current node root, the target node p and the stack stack used to store the path.
  4. In the getDisToPar function, first check whether the current node is empty, and if it is empty, return directly.
  5. Adds the current node's value to the stack.
  6. If the current node is the target node p and has not been visited before (visited is false), mark visited as true and return.
  7. If the target node p has not been found, first search recursively in the left subtree.
  8. If it is not found in the left subtree, it is searched recursively in the right subtree.
  9. If the target node p is not found in the left and right subtrees of the current node, it means that the current node is not on the path of the target node p, and it is popped from the stack.
  10. What is stored in the stack is the node value on the path from the root node to the target node p.

Tiktok SDE NG Round 2

The interviewer for this round was a white girl from Seattle. She chatted for 2 minutes and asked "how to optimize the database query performance" in the recent project, and then went directly to coding.

Coding 1

Q1:Given a nested list of integers (each element is an integer or a nested list), implement an iterator that goes through all integers in order. (Similar to LeetCode 341, but requires you to define your own data structure + implement next() and hasNext() )

Idea:First, clarify the "input format of nested lists" (the lady said to use Python's List[Union[int, List]]), use the stack to push the initial elements in reverse order, and loop to pop up the top element of the stack during hasNext(). If it is a list, continue to push its elements in reverse order until the top of the stack is an integer. While writing, I covered the use cases of "empty nested list" and "multi-level nesting". The lady asked "Why is the time complexity amortized O(1)".

class NestedIterator:
    def __init__(self, nestedList):
        # Initialize by pushing the list onto the stack in reverse order.
        # The top of the stack is always the next element to process.
        self.stack = nestedList[::-1]
    def next(self) -> int:
        # hasNext() guarantees the top of the stack is an integer, so we just pop it.
        return self.stack.pop()
    def hasNext(self) -> bool:
        # Loop until the stack top is an integer or the stack is empty
        while self.stack:
            top = self.stack[-1]
            
            # Case 1: Top is an integer. We found the next element.
            if isinstance(top, int):
                return True
            
            # Case 2: Top is a list. Pop it and push its contents back in reverse order.
            # Example: top = [1, 2] -> Pop it -> Push 2, then 1.
            top_list = self.stack.pop()
            self.stack.extend(top_list[::-1])
            
        return False
# --- Test Case ---
# Input: [[1,1], 2, [1,1]]
# Expected Output: [1, 1, 2, 1, 1]
nested_list = [[1, 1], 2, [1, 1]]
iterator = NestedIterator(nested_list)
result = []
while iterator.hasNext():
    result.append(iterator.next())
print(result) # Output: [1, 1, 2, 1, 1]

Coding 2

Q2:Given an array of strings, combine allophones together (requirement: time complexity better than O(nk log k), k is the maximum length of the string).

Idea:The conventional solution is to sort strings as keys, but the interviewer requires that O(k log k) be optimized for sorting. Use counting array to convert tuple as key (such as "aab" to (2,1,0,...,0)), so the processing of each string is O(k). When writing, the lady prompted "Can the product of prime numbers be used as the key?", and later added "The product of prime numbers may overflow, counting arrays are safer". The final code passed all test cases (including empty strings and single characters). After the interview, the young lady added, "Your counting array idea is more suitable for production scenarios than sorting."

from collections import defaultdict
from typing import List
def groupAnagrams(strs: List[str]) -> List[List[str]]:
    # Use defaultdict to handle missing keys automatically
    anagram_map = defaultdict(list)
    
    for s in strs:
        # Initialize a count array for 26 lowercase letters
        # count looks like: [2, 1, 0, ..., 0] for "aab..."
        count = [0] * 26
        
        for char in s:
            # Map char to index 0-25 using ASCII values
            count[ord(char) - ord('a')] += 1
        
        # Convert the list to a tuple to use it as a dictionary key
        # Time Complexity: O(K), where K is the length of the string
        key = tuple(count)
        
        anagram_map[key].append(s)
        
    return list(anagram_map.values())
# --- Test Case ---
strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
print(groupAnagrams(strs))
# Possible Output: [['eat', 'tea', 'ate'], ['tan', 'nat'], ['bat']]

Tiktok SDE NG third round of HM

The HM interview is quite important. The interviewer has the right to make the decision. Each interviewer has a different style. From experience, it is better to prepare based on the shortcomings of the first two rounds of interviews. This time the whole process was centered around the resume, and it felt like the interviewer paid more attention to communication and growth.

First, I introduced myself, then selected a few projects to ask questions, and also asked whether I was willing to take the initiative to take responsibility in the team, whether I was willing to learn new systems quickly, etc.

The key point is:1. Asked about the most challenging project. 2. How to collaborate with teammates. 3. How to deal with emergencies. I will simply share an internship experience, what caused the failure, and how to solve it in the end to avoid making the same mistake again. When answering, you should be round and clear, and some technical details should be understood. Generally, there is no problem. This time, I did not ask about coding. It is a normal chat. Whether it is appropriate will be decided based on your answer performance.

Contact us|Turn interview uncertainty into controllable results

In the real interview process, many sticking points are not "whether you can write", but whether you can explain your ideas clearly and answer key points in a limited time. Through our full-process interview assistance and OA support, students not only successfully completed the questions, but also clearly demonstrated their logical ability, problem-solving ability and engineering thinking during communication, allowing the interviewer to truly see "implementable strength."

Whether it's high-intensity coding on TikTok, follow-up, or in-depth project digging, our real-time assistance can help you stabilize the rhythm and complete key points at critical moments. This kind of improvement in ability will not only serve one interview, but will also feed back your way of solving real engineering problems in the long term.

If you are also preparing for TikTok/big factory OA or VO, and want to be more stable and confident in key interviews, please contact us immediately and take the opportunity into your own hands together.

Recommended Reading:

TikTok Acreage | TikTok MLE Intern VO Netizens say it's not difficult

Tiktok DE 3 rounds of VO interviews|Technical Digging + Modeling + Stressful Pacing

author avatar
Jack Xu MLE | Microsoft Artificial Engineer
Ph.D. From Princeton University. He lives overseas and has worked in many major companies such as Google and Apple. The deep learning NLP direction has multiple SCI papers, and the machine learning direction has a Github Thousand Star⭐️ project.
END