Two medium questions:
Had a optimal solution with minor bug for 1.
Explained the idea for 2 (implemented but did not have time to test - likely had bugs). I was too nervous and couldn't calm down to think.
I had actually solved 2 only two weeks ago :(
class Solution:
def isValidBST(self, root: TreeNode) -> bool:
st = collections.deque()
st.append((root, -float('inf'), float('inf')))
while st:
node, lower, upper = st.popleft()
if not node:
continue
if not lower < node.val < upper:
return False
left = node.left
right = node.right
st.append((left, lower, node.val))
st.append((right, node.val, upper))
return True