/96. Unique Binary Search Trees

96. Unique Binary Search Trees

Medium
Probability63.4% acceptance

Given a positive integer node_count, return the number of structurally unique binary search trees (BSTs) that can be constructed using node_count distinct values labeled from 1 to node_count. Each BST must use all node_count values exactly once.

Example 1

Input: 4

Output: 14

Explanation: There are 14 structurally unique BSTs that can be formed with 4 distinct values.

Example 2

Input: 2

Output: 2

Explanation: There are 2 structurally unique BSTs that can be formed with 2 distinct values.

Constraints

  • 1 <= node_count <= 19
  • Input node_count is an integer
Python (current runtime)

Case 1

Input: 5

Expected: 42

Case 2

Input: 6

Expected: 132

Case 3

Input: 7

Expected: 429