Skip to content

Check if a binary tree is symmetric or not #3471

@kumanoit

Description

@kumanoit

Is your feature request related to a problem? Please describe.
Check whether a binary tree is symmetric or not.

Describe the solution you'd like

  • Recursively check for left and right subtree of root
    1. left subtrees root's values should be equal right subtree's root value
    1. recursively check with left subtrees' left child VS right subtree's right child AND
  • left subtree's right child VS right subtree left child
    Ex.
    Below is a symmetric tree
                               1
                   /                         \
                 2                           2
         /                \             /             \
      3                    4         4                3

Below is not symmetric because values is different in last level

                               1
                   /                         \
                 2                           2
         /                \             /             \
      3                    5         4                3

Describe alternatives you've considered
Suggested optimal solution

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions