Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in the binary tree.
Leetcode 1448. Count Good Nodes in Binary Tree
Count how many nodes in a binary tree are "good", meaning their value is at least the maximum value seen on the path from the root to that node. This is solved by a tree traversal (DFS/BFS) that carries the current path maximum and increments the count when a node's value >= that maximum; n up to 10^5.
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.