Tap here to switch tabs
Problem
Submissions

Problem: Largest BST Subtree

Try to solve the Largest BST Subtree problem.

Statement

Given the root of a binary tree, find the largest subtree that is a valid Binary Search Tree (BST), and return the total number of nodes in that subtree.

Note: A subtree consists of a node and all of its descendants. A valid BST requires that for every node, all values in its left subtree are strictly smaller than the node’s value, and all values in its right subtree are strictly greater than the node’s value.

Constraints:

  • The number of nodes in the tree is in the range [0,104][0, 10^4].

  • −104≤-10^4 \leq Node.val ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Largest BST Subtree

Try to solve the Largest BST Subtree problem.

Statement

Given the root of a binary tree, find the largest subtree that is a valid Binary Search Tree (BST), and return the total number of nodes in that subtree.

Note: A subtree consists of a node and all of its descendants. A valid BST requires that for every node, all values in its left subtree are strictly smaller than the node’s value, and all values in its right subtree are strictly greater than the node’s value.

Constraints:

  • The number of nodes in the tree is in the range [0,104][0, 10^4].

  • −104≤-10^4 \leq Node.val ≤104\leq 10^4