Facebook | Phone interview
Company: Meta (Facebook)
Role: e3, e4
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
They asked 2 questions.
1. Given a sequence of integers and an integer total target, return whether a contiguous sequence of integers sums up to target.
I wasn't able to find it on leetcode but here's how I solved it using cache. I used hashmap in the real interview (and dumb enough to point out that I can use set at the end when I realized during the interview) to keep track of sum and counter of it. This because one of leetcode problem does the same.
Please feel free to share your feedback on the code below
Time complexity - o(n)
Space complexity - o(n)cache = set()
# this is so that if we have a target in the array. diff will be 0.cache.add(0)currSum = 0
for num in nums: diff = target - num currSum += num if diff in cache: return True cache.add(currSum)return False
2. Given a BST and a key, delete the corresponding node from the BST
https://leetcode.com/problems/delete-node-in-a-bst/description/
I will most probably fail since I wasn't able to complete the solution for 2nd problem but 🤞🏼
By the way, I am not sure if its new but meta lets you do a mock interview with one of their engineers and its invaluable. They give you feedback at the end of the mock interview. Also, above questions are not from mock interview but a real interview