Seção DSAMédio

Árvore Simétrica

Guia detalhado e implementação de Python para o problema da 'Árvore Simétrica'.

Declaração do problema

Médio

Escreva uma função is_symmetric(tree_arr) que pegue uma representação de array de uma árvore binária tree_arr e verifique se a árvore é simétrica (um espelho de si mesma em torno do centro, combinando estrutura e valores).

Restrições
  • 0 <= len(tree_arr) <= 1000

Exemplos

Example 1
Input
tree_arr = [1, 2, 2, 3, 4, 4, 3]
Output
True
Explanation

The tree is symmetric in both shape and node values.

Example 2
Input
tree_arr = [1, 2, 2, None, 3, None, 3]
Output
False
Explanation

Left child 2 has right child 3, right child 2 has right child 3. Values match but structures are not mirrors.

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.