CS-OA cs-vo Faang

Tiktok VO 真题 – Tiktok 面经 – tiktok oa – 一亩三分地 tiktok 面经 – tiktok面试难度

近期争议不断的tiktok现在处于即裁员又招聘的奇怪阶段,对于需要opt签证支持的候选人们来说,选tiktok也许是一个不错的选择,后面的事情只能先入行再说了。我们一起来看看本周tiktok的一道面试真题吧。

You are given a network of n nodes represented as an n x n adjacency matrix graph (if graph[i][j] == 1 then nodes i and j are connected) and a list of nodes ('initial') that are initially infected by malware. Malware will spread to connected nodes. M(initial) is the final number of nodes infected with malware after it spreads.

Example Input
(2-0-1) (3-4)
graph = [[1, 1, 1, 0, 0], graph[0][1]==1 and graph[0][2]==1 -> 0 is connected to 1 and 0 is connected to 2
[1, 1, 0, 0, 0],
[1, 0, 1, 0, 0],
[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1]]
initial = [1, 3] M(initial) = 5 (all nodes will be infected)

We will remove exactly one node from 'initial' (the node still has the same connections, it's just not initially infected)
NOTE: it can still be infected from other nodes

Return the node that, if removed from 'initial', would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return the node with the smallest value.

Example Output
output = 1
remove 1 -> M(initial) = 2 (3 and 4 will be infected)
remove 3 -> M(initial) = 3 (0, 1, and 2 will be infected)

这道题目是典型的图论和贪心算法结合的题目,涉及到网络中节点的感染传播和最小化感染影响的问题。下面是对这道题的评价以及一个简单的解题思路。

题目评价

  1. 综合性强:该题结合了图论(邻接矩阵表示的图)和贪心算法(寻找最优解),需要掌握多种算法和数据结构的知识。
  2. 实际应用广泛:类似的问题在网络安全、流行病传播控制等实际场景中都有应用。
  3. 难度适中:题目要求在复杂度较低的情况下(O(n^2))找到最优解,适合作为中等难度的面试题目。

解题思路

  1. 建模与理解
    • 用邻接矩阵表示图,理解节点之间的连接关系。
    • 初始感染节点列表表示一开始感染的节点。
  2. 模拟感染过程
    • 对于每个初始感染节点,模拟其感染过程,计算出最终感染的节点数。
    • 可以使用广度优先搜索(BFS)或深度优先搜索(DFS)来模拟感染的传播。
  3. 移除节点并计算影响
    • 对于初始感染列表中的每个节点,假设将其移除,然后重新模拟感染过程。
    • 记录每次移除后的最终感染节点数。
  4. 选择最优解
    • 比较所有可能移除的节点,选择使最终感染节点数最小的那个。
    • 如果有多个节点导致相同的最小感染节点数,选择编号最小的节点。

经过我们的面试辅助服务,候选人顺利通过了本轮面试,我们一起期待下一次的面试题目吧~

如果您对我们的服务感兴趣,随时留言咨询我们。

Leave a Reply

Your email address will not be published. Required fields are marked *