A command menu stores n commands with ids 1 to n in a binary search tree: for every node, smaller ids are in its left subtree and larger ids are in its right subtree.
Different insertion orders can give trees of different shapes. Write countTreeShapes(n) that returns how many structurally different binary search trees hold exactly the ids 1 to n. For n = 0 the empty tree counts as one shape.
Input: n = 3 Output: 5
Root 1 gives 2 shapes, root 2 gives 1, and root 3 gives 2.
Input: n = 1 Output: 1
A single node.
0 <= n <= 19Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #493 Count Menu Tree Shapes. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.