FastPrepCheck Binary Tree Height Balance
Problems/Check Binary Tree Height Balance

Check Binary Tree Height Balance

AMD logoAMD● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source asks to verify binary-tree height balance. The all-node definition, empty case, serialization, bounds and interface are authored conventional completion; approximate source match95%.

Return whether every node in the tree has left and right subtree heights differing by at most1. Height counts nodes on a longest downward path; a missing subtree has height0. The empty tree is balanced. Checking only the root is insufficient.

Function

isHeightBalanced(root: TreeNode) → boolean

Examples

Example 1

root = [3,9,20,null,null,15,7]return = true

At the root the subtree heights are1 and2, and every lower node also satisfies the difference bound.

Example 2

root = [1,2,null,3]return = false

The root has a left subtree of height2 and an empty right subtree of height0.

Constraints

  • 0 <= serialized tree length <= 400.
  • -1000 <= every non-null node value <= 1000.
  • The input is a valid acyclic binary tree serialized level by level, with null for a missing child; [] denotes an empty tree.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public boolean isHeightBalanced(TreeNode root) {
    // Write your code here.
}
Checking account…