Question bank › Binary Search Tree
Dsa Binary Search Tree Medium

Path Sum in BST

Write a program to determine if there exists a root-to-leaf path in a binary search tree (BST) such that the sum of the values along the path equals a given target sum. The program receives a BST in pre-order traversal and a target sum as input. You must print 'True' if such a path exists and 'False' otherwise. Input Format: - The first line contains space-separated integers representing the pre-order traversal of the BST. - The second line contains a single integer representing the target sum. Output Format: - Print 'True' or 'False'. Example: Input: 10 5 1 7 15 12 20 22 Output: True Input: 10 5 1 7 15 12 20 50 Output: False

Key concepts

binary_search_treepath_sumrecursive

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.