Even Odd 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
Number the levels of a binary tree from 0 at the root. A tree is called **Even-Odd** when both of these hold:
- On every **even-indexed** level, all values are **odd** and strictly **increasing** from left to right.
- On every **odd-indexed** level, all values are **even** and strictly **decreasing** from left to right.
Given the root of a non-empty binary tree, return true if it is Even-Odd, otherwise false. "Left to right" means the order in which a level-order traversal meets the nodes of that level, regardless of gaps.
Check each level in a BFS for O(n) time.
Examples
Constraints
- 1 <= number of nodes <= 10^5
- 1 <= Node.val <= 10^6
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.