Input Format
The locked stub code in your editor reads the following inputs and assembles them into a binary search tree:
The first line contains an integer, , denoting the number of nodes in the tree.
Each of the  subsequent lines contains an integer, , denoting the value of an element that must be added to the BST.
Output Format
The locked stub code in your editor will print the integer returned by your getHeight function denoting the height of the BST.
Binary search trees problem solution 30 days of code hackerrank

Problem solution in C++ programming language.

int getHeight(Node* root){
    if ( root == NULL ){
        return -1;
    }
    else{
        return 1 + max( getHeight(root->left), getHeight(root->right) );
    }
}

Problem solution in Java programming language.

public static int getHeight(Node root){
    if (root == null){
        return -1;
    }
    else{
        return 1 + Math.max( getHeight(root.left), getHeight(root.right) );
    }
}

Problem solution in JavaScript programming language.

public static int getHeight(Node root){
    if (root == null){
        return -1;
    }
    else{
        return 1 + Math.max( getHeight(root.left), getHeight(root.right) );
    }
}

Problem solution in PHP programming language.

 public function getHeight($root){
        if($root == null) {
            return -1;
        }
        
        return 1 + max($this->getHeight($root->left), $this->getHeight($root->right));
    }

Problem solution in Python programming language.

 def getHeight(self, root):
        if root == None:
            return -1
        else:
            return 1 + max( self.getHeight(root.left), self.getHeight(root.right) )

Problem solution in Ruby programming language.

 def getHeight(root)
        if root == nil
            return -1
        else
            return 1 + [self.getHeight(root.left), self.getHeight(root.right)].max
        end
    end
end

Problem solution in the Swift programming language.

func getHeight(root: Node?) -> Int {
        if let currentRoot = root {
            let leftHeight = getHeight(root: currentRoot.left)
            let rightHeight = getHeight(root: currentRoot.right)
            
            return 1 + max(leftHeight, rightHeight)
        }
        
     return -1
    }