828. All Paths for a Sum in Binary Tree

HardRecursionRecursion

Count root-to-leaf paths summing to target. Input: JSON {tree:[level-order,-1=null],target}.

Input: JSON {tree,target}.

Output: Integer.

Examples

Example 1
Input: {"tree":[5,4,8,11,-1,13,4,7,2,-1,-1,-1,-1,-1,1],"target":22}
Output: 1
Explanation: 5+4+11+2=22.
Example 2
Input: {"tree":[1,2,3],"target":3}
Output: 1
Explanation: 1+2=3.
Example 3
Input: {"tree":[1],"target":1}
Output: 1
Explanation: Root is leaf.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →