Height of a BST
Insert distinct values one by one into an empty binary search tree (smaller values go left, larger go right). Print the tree's height — the number of nodes on the longest root-to-leaf path.
Input
, then the distinct values in insertion order.
Output
The height.
Constraints
Sample 1
Input
5 50 30 70 20 40
Output
3
Sample 2
Input
3 1 2 3
Output
3