Practice Reverse Odd Levels of Binary Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Reverse Odd Levels of Binary Tree
Problem Statement
Given the root of a perfect binary tree, reverse the node values at each odd level of the tree. Return the root of the reversed tree. A binary tree is perfect if all parent nodes have two children and all leaves are on the same level. The level of a node is the number of edges along the path between it and the root node.
Source: Reverse Odd Levels of Binary Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [2,3,5,8,13,21,34]
[2,5,3,8,13,21,34]
# Example 2
root = [7,13,11]
[7,11,13]
# Example 3
root = [0,1,2,0,0,0,0,1,1,1,1,2,2,2,2]
[0,2,1,0,0,0,0,2,2,2,2,1,1,1,1]
Constraints
Related LeetCode Problems
Practice more problems similar to Reverse Odd Levels of Binary Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.