Problem Overview
The "Reverse Odd Levels of Binary Tree" problem (LeetCode 2415) requires reversing node values at odd-numbered levels (1, 3, 5, etc.) of a perfect binary tree, where the root is at level 0. Only values are swapped within each odd level; the tree structure remains unchanged.[1][7]
Full Problem Statement
Given the root of a perfect binary tree, reverse the node values at each odd level of the tree.
Input/Output Examples
| Example | Input Tree (level-order) | Output Tree (level-order) | Explanation | |---------|---------------------------|----------------------------|-------------| | 1 | [2][3][5][8] | [2][5][3][8] | Level 0: [2] unchanged. Level 1: [3][5] → [5][3]. Level 2: [8] unchanged. [5] | | 2 | [7] | [7] | Level 0: [7] unchanged. Level 1: → . [5] |
Constraints