← Walmart Labs Interview Insights

Walmart Labs·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Walmart Labs SWE interview, technical phone screen with a classic array merging problem. Pretty standard stuff but the in-place constraint is where they actually want to see if you know what you're doing.

Questions Asked (1)

Q1

You're given two sorted arrays, nums1 and nums2. nums1 has extra space at the end to fit all elements of nums2. Merge nums2 into nums1 in-place so the result is fully sorted. No extra array allowed.

Algorithms & Data Structures
Author's notes

The naive approach is to just copy everything into a temp array and sort it, but they'll push back on that immediately because of the in-place constraint.

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: compare the largest remaining elements and place the larger one at the end of nums1, moving backwards. This avoids overwriting elements in nums1 that haven't been merged yet and achieves O(m+n) time and O(1) space.

Pro tip: Emphasize that merging from the end is the key insight to avoid extra space and overwriting; mention that if you merged from the front, you'd need to shift elements, increasing time complexity.

1. Clarify inputs and constraints

Confirm that nums1 has length m+n with the first m elements being valid and the rest zeros, and nums2 has length n. Ensure in-place merging is required and no extra array is allowed.

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 at nums1[k], and 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, no action needed since they are already in place.

5. Analyze complexity

State that time complexity is O(m+n) and space complexity is O(1), as no extra data structures are used.

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)
  • Avoiding overwriting of unmerged elements in nums1
  • Edge cases: one array empty, all elements of one array larger than the other
  • Comparison with merging from the front and why it's inefficient

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