Reverse Odd Levels of Binary Tree
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given the root of a **perfect** binary tree: every internal node has two children and all leaves are on the same level.
Levels are numbered from 0 at the root. For every **odd** level, reverse the order of the node values on that level. For example, a level reading [2,1,3,4,7,11,29,18] becomes [18,29,11,7,4,3,1,2].
Only the values move; the tree shape stays the same. Return the root of the modified tree.
Examples
Constraints
- 1 <= number of nodes <= 2^14
- The number of nodes is `2^k - 1` for some `k >= 1`
- 0 <= Node.val <= 10^5
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.