Back to course home
0% completed
Vote For New Content
Solution: Reverse Odd Levels of Binary Tree
Problem Statement
Given the root node of a perfect binary tree, reverse the values of the nodes that are at odd-numbered levels (1, 3, 5, etc.).
- A perfect binary tree is one where all interior nodes have exactly two children and all leaf nodes are at the same level.
- The level of a node is counted from the root: the root is at level 0, its children are at level 1, and so on.
Return the root of the updated tree.
Note: Only the values are to be reversed — the structure of the tree must remain unchanged.
Examples
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible