← Meta Interview Insights

Meta·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Went through a Meta SWE coding round and got the classic remove duplicates from a sorted array problem. Pretty standard stuff but worth knowing cold.

Questions Asked (1)

Q1

Given a sorted integer array, remove duplicates in-place so each unique value appears once, using O(1) extra space. Return the count of unique elements.

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 (write) tracks the position for the next unique element, and the other (read) scans the array. Since the array is sorted, duplicates are adjacent, so compare the current element with the last written unique element and write only when different. Return the write pointer as the count of unique elements.

Pro tip: Clarify upfront that 'remove duplicates in-place' means modifying the input array and returning the new length, not creating a new array. Mention that the first element is always unique, so start the write pointer at index 1 and handle edge cases like empty or single-element arrays.

1. Clarify requirements and edge cases

Confirm that in-place modification is required, O(1) extra space, and that the return value is the count of unique elements. Discuss edge cases: empty array, single element, all duplicates.

2. Initialize two pointers

Set write pointer to 1 (since first element is always unique) and read pointer to 1. If array length is 0, return 0 immediately.

3. Iterate and compare

For each read pointer from 1 to n-1, compare nums[read] with nums[write-1]. If different, assign nums[write] = nums[read] and increment write.

4. Return the count

After the loop, write pointer equals the number of unique elements. Return write.

5. Analyze complexity

State that time complexity is O(n) because each element is visited once, and space complexity is O(1) since only two pointers are used.

Key Points to Mention

  • Two-pointer technique (read and write pointers)
  • Leveraging sorted property: duplicates are adjacent
  • In-place modification without extra space
  • Time complexity O(n) and space complexity O(1)
  • Edge cases: empty array, single element, all duplicates
  • Return value is the new length, not the modified array

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