Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Solution: Even Odd Tree
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given a binary tree, return true if it is an Even-Odd tree. Otherwise, return false.

The Even-odd tree must follow below two rules:

  1. At every even-indexed level (starting from 0), all node values must be odd and arranged in strictly increasing order from left to right.
  2. At every odd-indexed level, all node values must be even and arranged in strictly decreasing order from left to right.

Examples

Example 1

  • Input:
    1
   / \
  10  4
 / \
3   7
  • Expected Output: true

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible