FastPrepHeight-Balanced Binary Tree
Problems/Height-Balanced Binary Tree

Height-Balanced Binary Tree

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: In a 2023 write-up of Expedia's campus hiring for summer interns, this was the third coding task of the first face-to-face interview. The post names it only through a link to a well-known exercise on binary-tree balance. The author reports solving it the efficient way on the first attempt.

The post has no statement or limits. We chose these. Balanced means height-balanced, so at every node the two subtree heights differ by 1 or less, and an empty tree counts as balanced. The sizes are ours too: up to 500 nodes, with values from -10^4 to 10^4.

Our version is about 90% the same as the reported question.

You are given the root of a binary tree. Return true if the tree is height-balanced, and false otherwise.

The height of a subtree is the number of nodes on its longest path from its top node down to a leaf. An empty subtree has height 0.

A tree is height-balanced when, for every node, the heights of its left and right subtrees differ by at most 1. Checking only the root is not enough. An empty tree is height-balanced.

The node values do not affect the answer.

Function

isBalanced(root: TreeNode) → boolean

Examples

Example 1

root = [1,2,3,4,5,null,6]return = true
root
124536

Node 2 has two leaf children, so both of its subtrees have height 1. Node 3 has only a right child, so its subtree heights are 0 and 1. At the root, both subtrees have height 2. Every node passes, so the answer is true.

Example 2

root = [1,2,3,4,null,5,6,7,null,8]return = false
root
12473586

At the root, both subtrees have height 3, so the root itself is fine. But node 2 has a left subtree of height 2 (nodes 4 and 7) and no right child, so its subtree heights are 2 and 0, which differ by 2. The answer is false.

Example 3

root = []return = true
root
empty

The tree is empty. An empty tree has no node that can break the rule, so it is balanced. The answer is true.

Constraints

  • The tree has between 0 and 500 nodes.
  • -10^4 <= Node.val <= 10^4

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Binary Tree Level Order TraversalGoogle · ONSITE INTERVIEWGoogle interview questions
  • Lowest Common Ancestor Only When Both Targets ExistAdobe · ONSITE INTERVIEWAdobe interview questions
  • Sum Root-to-Leaf NumbersMeta · ONSITE INTERVIEWMeta interview questions
  • Binary Tree Maximum Path SumGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Balanced Tree Node ReportNetflix · ONSITE INTERVIEWNetflix interview questions
  • Trim a Binary Search TreeBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Maximum Value in a Binary TreeAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions
  • Count Uni-Valued SubtreesAmazon · PHONE SCREEN
  • Validate Binary Search TreeLyft · PHONE SCREENLyft interview questions

Interview reports that mention this question

  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isBalanced(TreeNode root) {
        // Write your code here.
    }
}
Checking account…