Objective
A binary tree is a BST if, for each node, all the values of its left subtree are smaller and all those of the right one are larger. It is not enough to compare a node with its direct children: the allowed range must be passed down. The first line has the number of nodes n; then come n lines value left right, where left and right are the indexes (from 0) of the children or -1 if there is no child. Node 0 is the root.
Instructions
- Show
Is a BSTorNot a BST(repeated values are not valid).
3
2 1 2
1 -1 -1
3 -1 -1
Is a BST
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise