← Meta Interview Insights

Meta·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Meta ML Engineer interview with a coding round that leaned on the classics. Nothing too exotic, but the in-place constraint is the kind of thing that trips you up if you haven't thought about it recently.

Questions Asked (1)

Q1

You have two sorted arrays, nums1 and nums2, with nums1 having extra space at the end to hold all elements. Merge nums2 into nums1 in-place so the result is sorted, without allocating a new array.

Algorithms & Data Structures
Author's notes

The trick is starting from the back, not the front.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a three-pointer technique starting from the end of both arrays to merge in-place without overwriting. Compare elements from the back and place the larger one at the end of nums1, moving pointers accordingly. This avoids extra space and runs in O(m+n) time.

Pro tip: Clarify that nums1 has length m+n with the first m elements valid and the rest empty, and nums2 has n elements. Mention that merging from the end prevents overwriting and is the optimal in-place solution.

1. Understand the problem and constraints

Confirm that nums1 has enough space (m+n) and that we must merge in-place. Identify m and n as the number of valid elements in nums1 and nums2 respectively.

2. Initialize pointers

Set three pointers: i = m-1 (last valid element in nums1), j = n-1 (last element in nums2), and k = m+n-1 (last position in nums1).

3. Merge from the end

While i >= 0 and j >= 0, compare nums1[i] and nums2[j]. Place the larger value at nums1[k], then decrement the corresponding pointer and k.

4. Handle remaining elements

If j >= 0 after the loop, copy remaining elements from nums2 into nums1. If i >= 0, the remaining elements are already in place.

5. Analyze complexity

State that time complexity is O(m+n) and space complexity is O(1) since we modify nums1 in-place.

Key Points to Mention

  • Three-pointer technique starting from the end to avoid overwriting
  • In-place merge without extra space
  • Time complexity O(m+n) and space complexity O(1)
  • Edge cases: one array empty, all elements of one array smaller/larger
  • Stability of merge (if equal, choose from nums1 to maintain order)
  • Comparison with naive approach that uses extra space

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.