Facebook | Phone Screen | Blew it. Ugh!! [Update]: Made it to virtual on-site
Company: Meta (Facebook)
Role: E3, E4
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Two medium questions:
1. https://leetcode.com/problems/merge-intervals/
2. https://leetcode.com/problems/validate-binary-search-tree/
Had an optimal solution with a 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