Skip to content

Practice Even Odd Tree

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1609
LeetCode Problem

Even Odd Tree

Problem Statement

Number tree levels from 0 at the root. On each even-numbered level, all node values must be odd and strictly increasing from left to right. On each odd-numbered level, all values must be even and strictly decreasing from left to right. Return whether root satisfies both conditions at every level.

Source: Even Odd Tree on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
root = [1,10,4,3,null,7,9,12,8,6,null,null,2]
Output
true

# Example 2

Input
root = [5,4,2,3,3,7]
Output
false

# Example 3

Input
root = [5,9,1,3,5,7]
Output
false

Constraints

The number of nodes in the tree is in the range [1, 10^5].
1 <= Node.val <= 10^6

Related LeetCode Problems

Practice more problems similar to Even Odd Tree.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.