How many shapes can an order-matching tree take?
Asked at Optiver
A price-ordered matching engine can be organized as a binary search tree over n distinct price levels 1..n. Two trees are different if their shapes differ. Count how many structurally distinct BSTs exist over n levels.
n = 3 -> 5
n = 4 -> 14
Return the number of distinct BST shapes on n keys (the nth Catalan number), in O(n^2) time.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.