Dsa
Binary Search Tree
Medium
Find Path with Given Sum in BST
Write a program to determine if there exist a root-to-leaf path in the binary search tree such that the sum of the values along the path equals a given sum. Print 'True' if such a path exists and 'False' otherwise.
Input Format:
- The first line contains an integer N, the number of nodes in the BST.
- The next N lines each contain an integer representing a node value.
- The last line contains an integer representing the target sum.
Output Format:
- Print 'True' if the path exists, otherwise 'False'.
Example:
Input:
5
5
4
8
11
2
22
Output:
True
Key concepts
binary_search_treepath_sumbacktracking
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