FunctionRacerProblemsRace

Unique Binary Search Trees

MediumDynamic programmingPython, JavaScript, TypeScript, Java, C++

Return how many structurally different binary search trees can be built from the values 1 to n, using each value exactly once.

Hint: pick a root r; the values below it form the left subtree and the values above it form the right subtree.

Example 1

n 3
returns 5

5 different shapes.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems