# Balanced Tree coding question | Aced

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3626/balanced-tree
Source observed: 2026-11-05T00:28:05.545Z
Last checked: 2026-11-05T00:28:05.545+00:00
Indexed: 2026-11-07T01:56:03.859+00:00

---

# Balanced Tree

**Difficulty:** Medium  
**Category:** [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms) · [Coding](https://www.aced.io/questions?type=coding)  
**Reported last asked:** a year ago  
**Interview experiences:** 4  
**Roles:** [Software Engineer](https://www.aced.io/questions?role=swe) (3)  
**Companies:** [Uber](https://www.aced.io/questions?company=uber), [Barclays](https://www.aced.io/questions?company=barclays), [Spotify](https://www.aced.io/questions?company=spotify)

## Problem

When using a tree data structure, insertion order can cause the tree to become unbalanced and affect program performance. We define a **balanced tree** as one where, for **every node**, the difference in height between its left and right subtrees is at most one.

Write a function `is_balanced(node)` that determines whether a binary tree is balanced.

- **Input:** The root node of a binary tree
- **Output:** `True` if the tree is balanced; `False` otherwise

Assume the root node conforms to this interface:

```text
class Node {
  left: Node
  right: Node
  value: any
}
```

Detailed company statistics and the solution are available through [Upgrade](https://www.aced.io/upgrade?src=questions). There are no community-contributed answers currently.

## Examples

### Example 1: Balanced

```text
Tree:       a
           / \
          b   c
         / \   \
        d   e   f

is_balanced(a) # => True
```

### Example 2: Balanced

```text
Tree:      a
          / \
         b   c
              \
               d

is_balanced(a) # => True
```

### Example 3: Not Balanced

```text
Tree:      a
          / \
         b   c
              \
               d
                \
                 e

is_balanced(a) # => False
```

### Example 4: Not Balanced

```text
Tree:       a
           / \
          b   c
         /     \
        d       e
       /         \
      f           g

is_balanced(a) # => False
```

Although the last tree appears symmetrical, it is not balanced because nodes `b` and `c` are not balanced.

The question interface includes expandable **Hint 1**, **Hint 2**, **Hint 3**, **Challenge 1**, **Challenge 2**, and **Challenge 3** sections, plus a code editor with **Editor**, **Share**, **Output**, **Test Results**, and **Console** panels. Use [Sign up to run code](https://www.aced.io/signup?src=lesson).

## Interview experiences

### Uber · a year ago

[Read the Uber software engineer interview experience](https://www.aced.io/experiences/uber-software-engineer-interview-301aa2)

**Role:** Software Engineer · Mid Level / L4

> “The process involved two coding rounds and a system design interview. The coding rounds went smoothly - I was comfortable with the data structures involved, including a question on binary indexed trees (Fenwick trees) for range sum queries. What didn't go well was the system design round; the interviewer gave very little feedback or direction, making it hard to gauge if I was on the right track. Communication from the recruiter between rounds was also slow.”

### Barclays · 2 years ago

[Read the Barclays software engineer interview experience](https://www.aced.io/experiences/barclays-software-engineer-interview-31230a)

**Role:** Software Engineer · Entry Level / L3

> “The process was pretty smooth and well organized. The recruiter gave a clear idea of what to expect, and the interviewers were friendly and easy to communicate with. The technical rounds were challenging but reasonable (LC mediums + system design). Behaviorals were much smoother than the technical rounds. Just focus on company values for behaviorals. One thing that caught me off guard was how quickly some of the questions escalated in difficulty, so time management was probably the hardest part.”

## Related question

- [Check if a given binary tree is height balanced.](https://www.aced.io/questions/1157/check-height-balanced-binary-tree)

## Related courses

### [Software Engineering Interview Prep](https://www.aced.io/courses/software-engineering)

![Software Engineering Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/4VkuYewBHUFIVUS5oJDW5h/02e833439b1289f25f38f13f81cbdca3/adobe_stock_optimized.jpeg?w=800&h=800&fm=webp&q=75)

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice data structures, algorithms, system design, people management, behavioral interviews, and more.

### [System Design Interviews](https://www.aced.io/courses/system-design-interviews)

![System Design Interviews](https://images.ctfassets.net/x78yjrjc11pq/78x7miFZFjBCrM5GqftrMJ/2f6d26e632c4e7265c49f6a180227edb/system_design_track_compressed_26ac98a46e__281_29_5be2280f31.jpeg?w=800&h=800&fm=webp&q=75)

Learn how to answer current system design questions across product, infrastructure, and AI domains. The course includes in-depth video examples, written breakdowns, reference patterns, and mock interview videos featuring senior engineers and managers.

## Explore Aced interview preparation

We are Aced, formerly Exponent. Our interview-preparation catalog includes courses for Product Management, Forward Deployed Engineering, Engineering Management, Software Engineering, System Design, Data Science, Machine Learning, Data Engineering, AI Engineering, Investment Banking, Generative AI, Security Engineer, TPM, Solutions Architect, UX / Product Design, and BizOps & Strategy.

- [All courses](https://www.aced.io/courses?src=nav)
- [Courses](https://www.aced.io/courses?src=nav)
- [Loops](https://www.aced.io/guides?src=nav)
- [Experiences](https://www.aced.io/experiences?src=nav)
- [All questions](https://www.aced.io/questions?src=nav)
- [Practice](https://www.aced.io/practice?src=nav)
- [Coaching](https://www.aced.io/coaching?src=nav)
- [Pricing](https://www.aced.io/upgrade?src=nav)
- [Log in](https://www.aced.io/login?src=nav)
- [Sign up](https://www.aced.io/signup?src=nav)

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3626%2Fbalanced-tree&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3626%2Fbalanced-tree). Opening a form does not execute a tool.