Unique Binary Search Trees

MediumBinary SearchMathLinked ListBinary Search TreeGraphTree

Description

Given an integer n, return the number of structurally unique BST's which has exactly n nodes of unique values from 1 to n.

Examples

Input:n = 3
Output:5
Explanation:

There are 5 unique BSTs with 3 nodes.

Input:n = 1
Output:1
Explanation:

With only 1 node, there is exactly 1 possible BST structure.

Input:n = 4
Output:14
Explanation:

With 4 nodes, the number of structurally unique BSTs is 14.

Constraints

  • 1 ≤ n ≤ 19

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!