← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta SWE coding round, one question, pretty classic but the in-place constraint is where things get interesting. Short session, nothing behavioral.

Questions Asked (1)

Q1

Given two sorted arrays where the first has extra space at the end to fit the second, merge them in-place so the result is sorted. For example, merging [1,2,5,7,0,0,0] and [3,4,6] should give [1,2,3,4,5,6,7].

Algorithms & Data Structures
Author's notes

My first instinct was to start from the front and shift elements right, which is the obvious wrong move because you end up doing a ton of unnecessary work.

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 fill the first array from back to front, avoiding the need to shift elements. Compare the largest remaining elements and place the larger one at the current end position, then move the pointers accordingly. This achieves O(m+n) time and O(1) extra space.

Pro tip: Clarify that the first array has exactly enough extra space to hold all elements of the second array, and handle edge cases like one array being empty. Mention that merging from the end is optimal because it avoids overwriting unmerged elements.

1. Understand the problem and constraints

Confirm that the first array has length m+n with n extra zeros at the end, and the second array has length n. The goal is to merge in-place without using extra space.

2. Initialize pointers

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

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 the remaining elements from nums2 into nums1. If i >= 0, the remaining elements are already in place.

5. Analyze complexity and edge cases

State that time complexity is O(m+n) and space complexity is O(1). Discuss edge cases: one array empty, all elements of one array smaller than the other, etc.

Key Points to Mention

  • Three-pointer technique starting from the end of both arrays
  • In-place merging without extra space
  • Time complexity O(m+n) and space complexity O(1)
  • Handling edge cases: empty arrays, all elements of one array smaller
  • Avoiding overwriting by filling from the back
  • Comparison of this approach to merging from the front (which would require shifting)

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