Unique Binary Search Trees II Problem

Unique Binary Search Trees II Problem — ExecCode Hard DSA Practice

Solve the Unique Binary Search Trees II problem on ExecCode. Free online hard DSA practice in DP. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description Imagine halving a search range each step on a sorted or monotonic input. Problem Given a positive integer n, count the number of structurally unique binary search trees (BSTs) that store values 1 through n. Two BSTs are considered different if their structure differs (even if node values are the same by the BST ordering). Return the total number of unique BSTs. Input Format A single line containing an integer n (1 ≤ n). The input appears exactly as the provided stdin string in the public testcases. Output Format A single integer: the number of unique BSTs that can be formed with values 1 through n. Constraints n is a positive integer. Typical test inputs are small (e.g., 1 and 3) but your solution should conceptually handle larger n within language limits.

Examples

Input {"raw": "3"}; Output 5. Input {"raw": "1"}; Output 1

Constraints

1<=N<=19

Practice Unique Binary Search Trees II free on ExecCode. Browse DSA problems, topic map, and placement guides.