Minimum Number of Operations to Have Distinct Elements
You are given an integer array nums.
In one operation, you remove the first three elements of the current array. If there are fewer than three elements remaining, all remaining elements are removed.
Repeat this operation until the array is empty or contains no duplicate values.
Return an integer denoting the number of operations required.
Example 1
Input
nums = [3,8,3,6,5,8]Output
1In the first operation, the first three elements are removed, leaving
[6, 5, 8], which are all distinct.Example 2
Input
nums = [2,2]Output
1After one operation, the array becomes empty, which meets the stopping condition.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^5