Grokking Tree Coding Patterns for Interviews
Ask Author
Back to course home

0% completed

Insufficient Nodes in Root to Leaf Paths (medium)
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 the root of a binary tree and an integer limit, remove all insufficient nodes from the tree, and return the root of the updated tree.

A node is insufficient if all root to leaf paths that include this node leads to a sum less than the limit. If a node is removed, all its descendants should also be removed.

A leaf is a node with no children.

Examples

Example 1:

  • Input: root = [5, 3, 8, 2, -1, null, 10], limit: 15
  • Expected Output: [5, null, 8, null, 10]
  • Explanation: The initial tree has 6 nodes

.....

.....

.....

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