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

0% completed

Vote For New Content
Solution: Insufficient Nodes in Root to Leaf Paths
On this page

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!

On this page