Problem Challenge 2

Structurally Unique Binary Search Trees (hard) #

Given a number ‘n’, write a function to return all structurally unique Binary Search Trees (BST) that can store values 1 to ‘n’?

Example 1:

Input: 2
Output: 2
Explanation: Here are all the structurally unique BSTs storing all numbers from 1 to 2:
Created with Fabric.js 1.6.0-rc.1 1 2 2 1

Example 2:

Input: 3
Output: 5
Explanation: Here are all the structurally unique BSTs storing all numbers from 1 to 3:
Created with Fabric.js 1.6.0-rc.1 1 2 2 1 3 3 3 1 2 3 2 1 1 2 3

Try it yourself #

Try solving this question here:

Output

0.473s

Total trees: 0 Total trees: 0

Mark as Completed
←    Back
Solution Review: Problem Challenge 1
Next    →
Solution Review: Problem Challenge 2