Tap here to switch tabs
Problem
Submissions

Problem: Remove Duplicates from Sorted Array II

med
30 min
Try to solve the Remove Duplicates from Sorted Array II problem.

Statement

Given an integer array nums sorted in non decreasing order, modify the array in place such that each unique element appears at most 22 times. The relative order of the elements must be preserved.

Return k, representing the number of valid elements in nums after removing the excess duplicates. The first k elements of nums must contain the final result. The elements remaining beyond the first k positions do not matter.

Constraints:

  • 1≤1 \leq nums.length ≤3imes104\leq 3 imes 10^4

  • −104≤-10^4 \leq nums[i] ≤104\leq 10^4

  • nums is sorted in non decreasing order.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Remove Duplicates from Sorted Array II

med
30 min
Try to solve the Remove Duplicates from Sorted Array II problem.

Statement

Given an integer array nums sorted in non decreasing order, modify the array in place such that each unique element appears at most 22 times. The relative order of the elements must be preserved.

Return k, representing the number of valid elements in nums after removing the excess duplicates. The first k elements of nums must contain the final result. The elements remaining beyond the first k positions do not matter.

Constraints:

  • 1≤1 \leq nums.length ≤3imes104\leq 3 imes 10^4

  • −104≤-10^4 \leq nums[i] ≤104\leq 10^4

  • nums is sorted in non decreasing order.