150 principais entrevistasMédio

Vista lateral direita da árvore binária

Guia detalhado e implementação de Python para o problema 'Binary Tree Right Side View'.

Declaração do problema

Médio

Dada a raiz de uma árvore binária, imagine-se do lado direito dela, retorne os valores dos nós que você pode ver ordenados de cima para baixo.

A árvore é representada como uma lista de ordem de nível. Implemente uma função rightSideView(root: list) -> list.

Restrições
  • The number of nodes in the tree is in the range [0, 100]
  • -100 <= Node.val <= 100

Exemplos

Example 1
Input
[1,2,3,None,5,None,4]
Output
[1,3,4]
Explanation

From the right side: at level 0 you see 1, at level 1 you see 3, at level 2 you see 4.

Example 2
Input
[1,None,3]
Output
[1,3]
Explanation

From the right side: at level 0 you see 1, at level 1 you see 3.

Example 3
Input
[]
Output
[]
Explanation

Empty tree, nothing to see.

Need a Hint?
Considere usar estruturas de dados específicas de árvores, como conjuntos ou heaps.
Edge Cases to Watch
  • Estruturas de entrada vazias
  • Entradas de elemento único
  • Grandes limites numéricos

Pronto para resolver?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Abrir no Editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Recursos Python recomendados

Expanda seu conhecimento com tutoriais interativos relacionados, folhas de dicas e comparações de código.