Implement in-place duplicate removal
MetaSoftware Engineer · Technical ScreenLast updated
This question evaluates proficiency in in-place array manipulation, handling duplicates in sorted sequences, and formal reasoning about space and time complexity.
Given a non-decreasing array of integers, overwrite it in-place so that each distinct value appears exactly once while preserving the order of the unique values. Return the new length of the compressed prefix and justify that your algorithm uses O(
- extra space and runs in O(n) time. Follow-up: modify your solution so that each value may appear at most twice, and explain the changes.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.