monk-watching-fight

Once Monk was watching a fight between an array and a tree, of being better. Tree got frustrated and converted that array into a Binary Search Tree by inserting the elements as nodes in BST, processing elements in the given order in the array. Now Monk wants to know the height of the created Binary Search Tree. Help Monk for the same. Note:

  1. In Binary Search Tree, the left sub-tree contains only nodes with values less than or equal to the parent node; the right sub-tree contains only nodes with values greater than the parent node.
  2. Binary Search Tree with one node, has height equal to 1. Input Format The first line will consist of 1 integer N, denoting the number of elements in the array. In next line, there will be N space separated integers, A[i], where 1 ≤ I ≤ N, denoting the elements of array. Output Format Print the height of the created Binary Search Tree.