Tap here to switch tabs
Problem
Submissions

Problem: Insufficient Nodes in Root to Leaf Paths

Insufficient Nodes in Root to Leaf Paths asks you to delete binary-tree nodes when every root-to-leaf path through them sums below a limit, then return the remaining tree. Node values may be negative.

Statement

Given the root of a binary tree and an integer limit, delete all insufficient nodes from the tree and return the root of the resulting binary tree.

A node is considered insufficient if every root to leaf path passing through that node has a sum strictly less than limit.

A leaf is a node with no children.

Constraints:

  • The number of nodes in the tree is in the range [1,5000][1, 5000].

  • −105≤-10^5 \leq Node.val ≤105\leq 10^5

  • −109≤-10^9 \leq limit ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Insufficient Nodes in Root to Leaf Paths

Insufficient Nodes in Root to Leaf Paths asks you to delete binary-tree nodes when every root-to-leaf path through them sums below a limit, then return the remaining tree. Node values may be negative.

Statement

Given the root of a binary tree and an integer limit, delete all insufficient nodes from the tree and return the root of the resulting binary tree.

A node is considered insufficient if every root to leaf path passing through that node has a sum strictly less than limit.

A leaf is a node with no children.

Constraints:

  • The number of nodes in the tree is in the range [1,5000][1, 5000].

  • −105≤-10^5 \leq Node.val ≤105\leq 10^5

  • −109≤-10^9 \leq limit ≤109\leq 10^9