Gamified challenge · BST property
tree is a ranking tree of player scores in level order with null for a missing spot (TreeNode in code). It is valid when, for every player, all scores in their left subtree are strictly smaller and all scores in their right subtree are strictly bigger. Scores can be any 32-bit integers.
Write isBst(tree) (Python: is_bst(tree)) that returns true if the tree is valid and false otherwise. An empty tree is valid. Checking each node only against its own children is not enough.
[2, 1, 3] is valid. [5, 3, 8, 1, 6, 7, 9] is not: 6 is a fine right child of 3, but it sits in the left subtree of 5 and 6 > 5.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google