Remove Duplicates from Sorted Array II Problem
Remove Duplicates from Sorted Array II Problem — ExecCode Easy DSA Practice
Solve the Remove Duplicates from Sorted Array II problem on ExecCode. Free online easy DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given a sorted array, keep each distinct value at most twice. Use write as the length of the valid prefix, and compare the current value with nums[write - 2].
Examples
Input nums = [1,1,1,2,2,3]; Output 5. Input nums = [0,0,0,1,1,1,1,2,3,3]; Output 7
Constraints
1 <= nums.length <= 3 * 10^4 -10^4 <= nums[i] <= 10^4 nums is sorted in non-decreasing order.
Practice Remove Duplicates from Sorted Array II free on ExecCode. Browse DSA problems, topic map, and placement guides.