# Validate Bst

![](https://3743232000-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHW2IQuh2PFpWJDvBz2FF%2Fuploads%2Fgit-blob-8e5441758e5dc7110975a38339adeaddae98c593%2FScreenshot%202023-01-21%20at%2022.46.50.png?alt=media)

*

```jsx
// This is an input class. Do not edit.
class BST {
  constructor(value) {
    this.value = value;
    this.left = null;
    this.right = null;
  }
}

function validateBst(tree) {
  return validateHelper(tree, -Infinity, Infinity)
}

function validateHelper(node, min, max) {
  if (node === null) {
    return true;
  }

  if (node.value < min || node.value >= max) {
    return false;
  }

  const left = validateHelper(node.left, min, node.value);
  const right = validateHelper(node.right, node.value, max);

  return left && right;
}

// Do not edit the line below.
exports.BST = BST;
exports.validateBst = validateBst;
```
