Merge two n-ary trees. Given roots of 2 n-ary trees, write code to merge them following specific rules: 1) If nodes have the same name at the same level, combine their children and use the value from the second tree. 2) If a node has no corresponding match, add it directly. 3) Preserve the order of nodes based on their original position in both trees.
Leetcode 617. Merge Two Binary Trees
Given two binary trees, merge them into a new tree by traversing both from the roots and summing the values of overlapping nodes while using the non-null node when one side is missing. This is typically solved with a simultaneous DFS/BFS traversal (often recursive) that combines corresponding nodes.
Onde essa pergunta já apareceu
Use esses exemplos para entender em que contexto ela costuma cair e adaptar sua prática.
Materiais associados
Nenhum anexo público associado a esta pergunta.
Depois de treinar essa pergunta, vale abrir outras do mesmo tipo e da mesma senioridade para comparar padrões de resposta.
Isso ajuda a sair da memorização de uma resposta só e entrar em repertório real de entrevista.
Continue a preparação com o banco completo
No app você encontra perguntas parecidas, compara empresas e aprofunda essa busca com mais filtros.