Medium · Trees

Path sum to K

Given the root of a binary tree and an integer k, return the number of downward paths whose node values sum to k. A path may start and end at any nodes, including a single node, but must run from parent to child.

Examples

Example 1

k = 8

Output: 2 paths

Example 2

k = 7

Output: 3 paths

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Trees problems