Level: Senior-Level
Round: Full Journey · Type: Coding · Difficulty: 5/10 · Duration: 120 min · Interviewer: Neutral
Topics: Binary Search, Arrays, In-place Hashing
Location: San Francisco Bay Area
Interview date: 2025-12-28
I was asked two coding questions.
Question 1: Search Insert Position
The prompt was:
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
Example 1:
Input: nums = [1,3,5,6], target = 5 Output: 2
Example 2:
Input: nums = [1,3,5,6], target = 2 Output: 1
Example 3:
Input: nums = [1,3,5,6], target = 7 Output: 4
My code:
` def searchInsert(nums, target): left, right = 0, len(nums) - 1
while left <= right:
mid = (left + right) // 2
if nums[mid] == target:
return mid
elif nums[mid] < target:
left = mid + 1
else:
right = mid - 1
return left
`
Question 2: Find All Numbers Disappeared in an Array
The prompt was:
Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.
Example 1:
Input: nums = [4,3,2,7,8,2,3,1] Output: [5,6]
Example 2:
Input: nums = [1,1] Output: [2]
My code:
` def findDisappearedNumbers(nums): for i in range(len(nums)): index = abs(nums[i]) - 1 nums[index] = -abs(nums[index])
return [i + 1 for i in range(len(nums)) if nums[i] > 0]
`
Hints:
return left is the key (insertion position).LeetCode similar: LeetCode 35, LeetCode 448