Downward paths adding to a target
Write count_paths(root, target): count the downward paths in a binary tree whose values add up to target. A downward path starts at any node and follows child links down for zero or more steps, so it may start and end anywhere, but it never goes up. Values can be negative or zero, so a sum that passes the target can come back to it. An empty tree has no paths. Each TreeNode has val, left and right.
The tests call the provided run_count_paths(values, target), where values lists the tree level by level with null for a missing child: [1, null, 2, 3] is a root 1 with only a right child 2, whose left child is 3.
Aim for one pass over the tree, not a new search from every node.
Besides the tests, one large input (a 4,695-node tree, 612 levels tall) with a ~130 ms limit (scaled to your device's speed): brute force won't pass.
Examples
run_count_paths([1,2,3], 3)→2run_count_paths([4,2,-1,1,3,5,null,null,null,1,null,-4], 5)→2run_count_paths([], 0)→0