Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Insufficient Nodes in Root to Leaf Paths

XPChallenge Points: 220
levelLevel: Medium

Given a binary tree root and an integer limit, delete all insufficient nodes simultaneously and return the new root.
A node is insufficient if every root→leaf path that goes through it has total sum strictly less than limit.
A leaf has no children.

Example 1:

Input: root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22

Output: [5,4,8,11,null,17,4,7,null,null,null,5]

Example 2:

Input: root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1

Output: [1,2,3,4,null,null,7,8,9,null,14]

Example 3:

Input: root = [1,2,-3,-5,null,4,null], limit = -1 Output: [1,null,-3,4]

Output: [1,null,-3,4]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result