Question bank › Binary Search Tree
Dsa Binary Search Tree Medium

K-Left-Turn Discovery

In a BST, every path from the root involves a series of left and right turns. Given a BST and an integer K, identify all keys in the tree where the path from the root to that key contains exactly K 'left turns'. Input: The first line contains space-separated integers for the BST. The second line contains the integer K. Output: Space-separated integers (the keys) in ascending order. Example: Input: 10 5 15 2 7 12 20 1 Output: 5 7 12 Explanation: - 5: 10->5 (1 left turn) - 7: 10->5->7 (1 left turn, 1 right turn) - 12: 10->15->12 (1 right turn, 1 left turn) - 2: (2 left turns, invalid)

Key concepts

binary_search_treepath_traversaltree_depth

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.