class Solution:
    def is_valid_bst(self, node):
        return self.helper(node, float('-inf'), float('inf'))
    
    def helper(self, node, min_value, max_value):
        if not node:
            return True
        
        if node.value < min_value or node.value > max_value:
            return False
        
        return (
            self.helper(node.left, min_value, node.value)
            and self.helper(node.right, node.value, max_value)
        )
    
    def is_valid_bst2(self, node):        
        self.is_valid = True
        self.prev_value = float('-inf')
        self.in_order(node)
        return self.is_valid
    
    def in_order(self, node):
        if not node or not self.is_valid:
            return
        
        self.in_order(node.left)

        if node.value <= self.prev_value:
            self.is_valid = False
            return
        self.prev_value = node.value
        
        self.in_order(node.right)
