> For the complete documentation index, see [llms.txt](https://algorithm.prettylog.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://algorithm.prettylog.com/algorithm-problems/algoexpert/medium/validate-bst.md).

# Validate Bst

![](/files/YNsSg55IUMSkLzqws6BZ)

*

```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;
```
