96. Unique Binary Search Trees
Blog Given an integer n , return the number of structurally unique BST 's (binary search trees) which has exactly n nodes of unique values from 1 to n . Example: 1 Input: n = 3 Output: 5 Example: 2 Input: n = 1 Output: 1 Constraints: 1 Important observation for solving the problem: If we keep K as our root, then, all numbers lower than K will come in left subtree and all numbers greater than 1 will come in right subtree. Also, if we have X ways of forming left subtree and Y ways of forming right subtree, then, total number of trees rooted at K can be calculated as : ways(K) = ways(X) * ways(Y...