## How to avoid Integer Overflow when comparing two node valued in BST?

For example, if here are one BST as: [Integer.MIN_VALUE, Integer.MIN_VALUE] If I want to compare if the left child node is smaller or equal to parent nod – 1, the value gonna be overflow. In this case, don’t use Integer.MIN_VALUE, use null as the default instead. Here is an example about using null as comparison …

## Recover Binary Search Tree

This is No.99 in LeetCode. Here are approaches to this problem: Approach 1: Sort an Almost Sorted Array Where Two Elements Are Swapped Algorithm Here is the algorithm: Construct inorder traversal of the tree. It should be an almost sorted list where only two elements are swapped. Identify two swapped elements x and y in …

## How to construct a BST with a given pre-order array?

Code is below: // build the tree private TreeNode build_tree( String[] node, int min, int max ){ // invalid corner case if( idx >= node.length ){ return null; } TreeNode root = null; // valid value if( Integer.valueOf(node[idx]) > min && Integer.valueOf(node[idx]) < max ){ // build the root root = new TreeNode( Integer.valueOf( node[idx]) …