medium10 pts · first answer countsgraphsbinary-search-treedebugging
Bug in a parent-child BST check
This function checks only that each left child is smaller and each right child is larger than its parent. Why is it wrong?
function isBST(n) {
if (!n) return true
if (n.left && n.left.val >= n.val) return false
if (n.right && n.right.val <= n.val) return false
return isBST(n.left) && isBST(n.right)
}Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Python default list surpriseBackend Developer
- Edges in a tree with n nodesBackend Developer
- Most nodes in a binary tree of height 3Backend Developer
- What inorder traversal of a BST givesBackend Developer
- Preorder output of a small treeBackend Developer
- Traversal for freeing a whole treeBackend Developer
- Data structure for level-order traversalBackend Developer