Unique Binary Search Trees

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

Example 1
Inputn = 3
Output5
There are 5 structurally unique BSTs that can store the values 1, 2, and 3.
Example 2
Inputn = 1
Output1
With only one value, there is exactly one possible BST.

Constraints

  • 1 <= n <= 19

Asked at 11 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate