← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Meta coding screen, pretty standard array manipulation problem. Nothing fancy but the in-place constraint is where people slip up.

Questions Asked (1)

Q1

Given a sorted integer array, remove duplicates in-place so each value appears exactly once, then return the count of unique elements. You must do this with O(1) extra memory.

Algorithms & Data Structures
Author's notes

Two-pointer approach is the move here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique: one pointer (i) tracks the position of the last unique element, and the other (j) scans the array. When a new unique element is found (nums[j] != nums[i]), increment i and copy nums[j] to nums[i]. Finally, return i+1 as the count of unique elements.

Pro tip: Clarify that the array is sorted and that we only need to return the count, not the modified array itself. Also, mention that the relative order of unique elements is preserved, which is often expected.

1. Understand the problem and constraints

Restate the problem: remove duplicates in-place from a sorted array, return the number of unique elements, and use O(1) extra memory. Confirm that the array is sorted and that we can modify it.

2. Choose the two-pointer approach

Explain that since the array is sorted, duplicates are adjacent. Use two pointers: one to track the last unique element (i) and one to scan the array (j).

3. Walk through the algorithm

Initialize i = 0. Iterate j from 1 to n-1. If nums[j] != nums[i], increment i and set nums[i] = nums[j]. After the loop, return i+1.

4. Analyze complexity and edge cases

Time complexity is O(n) since we traverse the array once. Space complexity is O(1) as we only use two pointers. Handle edge cases: empty array (return 0), single element (return 1), all duplicates (return 1).

5. Test with examples

Walk through a small example, e.g., [1,1,2] -> length 2, array becomes [1,2,_]. Also test [0,0,1,1,1,2,2,3,3,4] -> length 5, array becomes [0,1,2,3,4,_,_,_,_,_].

Key Points to Mention

  • The array is sorted, so duplicates are adjacent.
  • Two-pointer technique: i for unique elements, j for scanning.
  • In-place modification: only overwrite elements after i.
  • Return i+1 as the count of unique elements.
  • Time complexity O(n), space complexity O(1).
  • Edge cases: empty array, single element, all duplicates.

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