Problem Statement

Pattern:


Iterative Inorder Stack Solution

public boolean isValidBST (TreeNode node){
	Deque<TreeNode> stack = new LinkedList<>();
	TreeNode prev = null;
	while(node!= null || !stack.isEmpty()) {
		if(node != null) {
			stack.push(node);
			node = node.left;   // go left
		} else {
			node = stack.pop(); // visit node
			if(prev != null && prev.val >= node.val) return false;
			prev = node;
			node = node.right;  // go right
		}
	}
	return true;
}

Notes

Range Solution

leetcode solution