Problem
You get the root of a binary tree and an integer targetSum. The input shows the tree as a list in level order. This order lists the nodes one level at a time, from left to right. A null value marks a missing child.
A downward path is a list of nodes where each node is a child of the node before it. The path can start at any node and stop at any node below it. A path with only one node is also a downward path.
Return the number of downward paths whose node values add up to targetSum.
Example 1
- Input:
- root = [5,3,-2,3,2,null,1], targetSum = 3
- Output:
- 3
- Explanation:
- Three paths have the sum 3:
5 -> -2, the left child of the root alone, and the left child of that node alone.
Example 2
- Input:
- root = [1,-1,1,null,1], targetSum = 1
- Output:
- 4
- Explanation:
- The four paths are the root alone,
1 -> -1 -> 1, the right child of the root alone, and the child of-1alone.
Example 3
- Input:
- root = [2], targetSum = 5
- Output:
- 0
Constraints
- 0 <= number of nodes <= 1000
- -10^9 <= Node.val <= 10^9
- -1000 <= targetSum <= 1000
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Binary Tree Maximum Path Sum
Coding · Binary Tree · Depth-First Search · DP on Trees
- Path Sum II
Coding · Backtracking · Binary Tree · Depth-First Search
- Binary Search Tree to Greater Sum Tree
Coding · Binary Search Tree · Binary Tree · Depth-First Search
- All Nodes Distance K in Binary Tree
Coding · Binary Tree · Breadth-First Search · Depth-First Search
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 437. Path Sum III
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 1 record
TikTok
Path Sum III
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 62.1. This is not an interview probability.
View source