Find a valid root node in a colored tree. Given a tree with n nodes, each colored 'R', 'A', or 'W', determine if there exists a node that can serve as the root of a binary tree such that the colors follow one of six possible repeating 3-color patterns level by level. Return the index of a valid root node if it exists, or -1 if no solution exists. The tree has at most 3 neighbors per node, and the time complexity should be O(V).
Find Root Node in Colored Tree with Pattern Constraints
Given an undirected connected acyclic graph where each node has at most 3 edges and nodes are colored (Red/Black/White or similar color patterns), find a root node such that when the graph is viewed as a binary tree from that root, it satisfies specific color pattern constraints across levels (e.g., RBWRBW repeating pattern or alternating colors). Return -1 if no valid root exists.
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.