注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
Passed but didn't complete team match. Pretty hard. During team match hiring manager ask may ask you System Design questions out of no where.
Round 1: TikTok 3474. Lexicographically Smallest Generated String
- Problem Overview: You are given two strings,(consisting of 'T' and 'F') of length n, andof length m. You need to generate the lexicographically smallest string of length n + m - 1.
- If, the substring starting at index i of length m must equal.
- If, the substring starting at index i of length m must not equal.
- Core Strategy (Greedy + Two-Pass):
- Initialize: Build an array of length n + m - 1 filled initially with 'a' to keep it lexicographically smallest.
- Pass 1 ('T' Constraints): Iterate through. Whenever you encounter a 'T', lock in the characters ofat those positions. If a conflict occurs (a position is already locked with a different character), return. Mark these positions as "fixed".
- Pass 2 ('F' Constraints): Check every 'F' window. If a window accidentally matches, you must break the equality by changing the rightmost unfixed character in that window to 'b'. If no unfixed character is available to change, it's impossible, so return.
Round 2: TikTok BFS (Escape Virus / Contain Virus)
- Similar Problem: LeetCode 749. Contain Virus.
- Problem Overview: A grid has uninfected cells (0) and infected cells (1). Each round, the virus spreads to adjacent uninfected cells by 1 step. Resources are limited, so each day you must choose one contiguous viral region that threatens the most uninfected cells and quarantine it by building walls around its perimeter.
- Core Strategy (Simulation + BFS/DFS):
- Identify Regions: Use BFS or DFS to find all disconnected continuous blocks of infected cells (1s).
- Evaluate Threat: For each region, calculate two things: the number of uninfected cells it will infect next night, and the number of walls required to quarantine it (its perimeter).
- Greedy Action: Select the region with the maximum threat, permanently wall it off (add its perimeter to your total wall count, and mark its cells as contained), and let all other active virus regions spread by 1 step. Repeat until no active uninfected cells or uncontained viruses remain.
Round 3: TikTok Calculate Elements (Parsing Chemical Formulas)
- Problem Overview: Given a chemical formula string containing nested parentheses, numbers, and element names (e.g.,,), compute the total count of each element (like total Hydrogen and total Oxygen). This is identical to LeetCode 726: Number of Atoms.
- Core Strategy: Use a Stack or Recursion to handle nested parentheses and multipliers.
- Traverse the string from right-to-left (or use a stack for left-to-right).
- When you encounter numbers, parse the full integer multiplier.
- When you encounter closing parentheses ), push a new scope onto the stack.
- When you encounter opening parentheses (, pop the scope, multiply all element counts inside by the multiplier immediately following the closing parenthesis, and merge them into the outer scope.
Example Walkthrough:- Inner Group :
- Containswith count 1.
- Multiplier after )2 is 2, socount = 1 * 2 = 2.
- Outer Group :
- Inside we have(count 1) and the inner group(count 2). Total inside:.
- Multiplier after this parenthesis is 2, so we multiply everything inside by 2:,.
- Leading :
|