You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if not (node.val>left and node.val<right): # checking the left value is less than node and right value is greater than node
return False
return (valid(node.left,left,node.val) and valid(node.right,node.val,right)) # recursively calling left child and right child and returing the result True if both are true else False
return valid(root,float("-inf"),float("inf")) #calling recursive function to check