Dsa
Binary Search Tree
Hard
Binary Search Tree Validate Structure
Given a binary tree, determine if it is a valid binary search tree (BST).
Input Format:
The first line contains an integer n, the number of nodes in the tree.
The second line contains n space-separated integers representing the values of the nodes in a pre-order traversal (-1 for null).
Output Format:
Print 'True' if the tree is a valid BST, otherwise print 'False'.
Example:
Input:
5
4 2 1 -1 -1 3 -1 -1 6 -1 -1
Output:
True
Key concepts
binary_treevalidate_bstrecursive
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