TikTok software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
n broadcast stages, numbered 1 to n, arranged in a perfect binary tree rooted at stage 0. Each stage...Input: Binary treeStreamBuffer 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)'S' - your starting position - 'C' - the...Input: 2D gridcategories 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 signaturelargest_category_value(categories: str, dependencies: list[list[int]]) -> int{"categories":"abaca","dependencies":[[0,1],[0,2],[2,3],[3,4]]}3
0 → 2 → 3 → 4 has categories "aaca". Category a appears three times, and no path contains more occurrences of any category.Example 2:{"categories":"a","dependencies":[[0,0]]}-1
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.[0, n - 1].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.def find_scc(graph: List[List[int]]) -> List[List[int]]:graph = [[1], [2], [0], [4], [5], [4]] [[0, 1, 2], [4, 5]] 4 follows 5.graph = [[1], [], [3], [2]] [[0, 1], [2, 3]] 0 connects to 1, forming an SCC. Nodes 2 and 3 form another because each can reach the other.1 <= graph.length <= 1000 0 <= graph[i].length <= graph.length Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free