CodingDojo icon indicating copy to clipboard operation
CodingDojo copied to clipboard

[Challenge] Invert Binary Tree

Open drkennetz opened this issue 3 years ago • 3 comments

Invert Binary Tree

The classic algorithm problem that you see on all the coding interview prep advertisement sites! The challenge is simple: Write a function that takes in a Binary Tree and Inverts It. In other words, the function should swap every left node in the tree for its corresponding right node.

Each BinaryTree node has an integer value, a left child node, and a right child node. Children nodes can either be BinaryTree nodes themselves or None / null / nil.

Business Rules/Errata

  • The operation should modify the input tree - other objects should not be created to complete this challenge.

Examples

Sample Input

tree =        1
           /     \
         2        3
       /   \    /   \
      4     5  6     7
    /   \
   8     9

Sample Output

tree =        1
           /     \
          3       2
        /   \   /   \
       7     6 5     4
                   /   \
                  9     8

drkennetz avatar Jul 13 '22 02:07 drkennetz

Hi, this challenge makes part of hacktoberfest? @drkennetz

JulioCVaz avatar Oct 26 '22 01:10 JulioCVaz

@JulioCVaz this one hasn't been implemented yet, but if you solve any challenge we've already posted under the "challenges" folder, we'll accept them with the hacktoberfest-accepted label and they'll count. You either have to solve the challenge in a new language, or find a different solution than one that has already been posted.

drkennetz avatar Oct 26 '22 01:10 drkennetz

@drkennetz nice! I'll participate

JulioCVaz avatar Oct 26 '22 01:10 JulioCVaz