Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Even Odd Tree

Medium

Topics
TreeBFS

A binary tree is even-odd if: on even-indexed levels (root is level 0) every node has an odd value and values are in strictly increasing order left to right; on odd-indexed levels every node has an even value and values are in strictly decreasing order. Return whether the tree is even-odd.

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

Constraints

  • 1 <= number of nodes <= 10^5
  • 1 <= Node.val <= 10^6
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access