Company: Oracle_27thjuly
Difficulty: medium
Valid BST Permutations A binary tree is either empty ( root = null ), or a root node holding a value together with a left subtree and a right subtree, each of which is again a binary tree. A binary tree is a binary search tree (BST) when, for every node, all values in its left subtree are smaller than the node's value and all values in its right subtree are greater than the node's value. You are given n queries. For a query value k , count how many structurally different BSTs can be built that contain exactly the keys 1, 2, ..., k , each key used once. The counts grow very quickly, so report each one modulo 100000007 (that is, 10^8 + 7 ). Implement numBST(nodeValues) , which returns the answers for all queries in input order. Input The first line contains an integer n , the number of queries. Each of the next n lines contains one integer nodeValues[i] . Output Print n lines. Line i holds the number of different BSTs on the keys 1..nodeValues[i] , modulo 100000007 . Constraints 1 <=