True Story:
Meet it in the 2nd round phone interview of facebook summer 2020 Phd Machine Learning SDE intern on Dec 12th, 2019.
Unfortunately I fail to answer this question, which looks simple nowadays.
This leads to a rejection, which is the first rejection I received from facebook.
Later I took another 2-round phone interview on May 11th, 2020 for fall intern Core Data Scientist. I got rejection again, maybe due to HC issues, since I believed I answered really well during the interview.
Today I met this question again, and I solved it quickly. Hopefully I will take another interview with facebook for full time position several months in the future. Look forward to what the story will be like at that time.
class Solution:
def missingElement(self, nums: List[int], k: int) -> int:
#TC: O(len(nums))
#SC: O(1)
for i in range(len(nums) - 1):
gap = nums[i+1] - nums[i] - 1
if gap < k:
k -= gap
else:
return nums[i] + k
return nums[-1] + k