Facebook | Phone Screen | Blew it. Ugh!! [Update]: Made it to virtual on-site
Anonymous User
4590

Two medium questions:

  1. https://leetcode.com/problems/merge-intervals/
  2. https://leetcode.com/problems/validate-binary-search-tree/

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
Comments (7)