Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Solution: Balanced Binary 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

Determine if a binary tree is height-balanced.

A binary tree is considered height-balanced if, for each node, the difference in height between its left and right subtrees is no more than one.

Examples:

  1. Input:
    3
   / \
  9  20
     / \
    15  7
  • Expected Output: true
  • Justification: Every node in the tree has a left and right subtree depth difference of either 0 or 1.
  1. Input:
        1
      /   \
     2     2
    / \   / \
   3   3 3   3
  / \       / \
 4   4     4   4
  • 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