Question bank › Trees
Dsa Trees Medium

Path Sum Counter

Given a binary tree, find the number of paths that sum to a given value. A path is defined as any sequence of nodes in the tree where the sum of the node values equals the target sum. The input consists of the first line with the target sum (an integer), followed by the tree's node values in level order, where 'null' indicates absent nodes. The output should be a single integer representing the number of paths that sum to the target. Example Input: 22 5 4 8 11 null 13 4 7 2 null null null null 5 1 null null Example Output: 3

Key concepts

treespathsum

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.