Binary Search Tree Validator
Hard
binary-tree
validation
recursion
Problem Description
Check if a binary tree is a valid binary search tree.
Input Format
Space-separated node values in level-order (use -1 for null nodes)
Output Format
Print "VALID" if BST, "INVALID" otherwise
Constraints
1 ≤ number of nodes ≤ 1000, -1000 ≤ node values ≤ 1000
Sample Input/Output
Input:
5 3 8 2 4 7 9
Output:
VALID
Explanation
Tree satisfies BST property: left < root < right for all nodes
Solution Hints
- Read carefully: Understand input/output format and constraints
- Start simple: Think of brute force solution first, then optimize
- Edge cases: Consider empty inputs, single elements, max constraints
- Data structures: Choose arrays, hash maps, sets based on problem needs
- Time complexity: Ensure your solution fits within time limits
- Test examples: Verify logic with provided sample inputs
290
Points
Points
2000ms
Time Limit
Time Limit
256MB
Memory Limit
Memory Limit
Code Editor
Register to Access Code Editor
Create a free account to solve coding problems and track your progress.
Register Now