You are given an array nums. Your goal is to make all the numbers in the array different from each other.
To do this, you are allowed to perform the following action repeatedly:
Remove exactly 3 elements from the start (front) of the array.
If fewer than 3 elements remain, remove all of them.
An empty array or an array with no duplicate values is already valid.
Your task is to determine the minimum number of such removal operations required so that the array has only distinct elements.
Input: nums = [3,1,3,2,4,2]
Output: 1
Explanation:
Initial array has duplicates (3 and 2 occur twice). Remove first 3 elements → [2,4,2] Still duplicates → but we only needed 1 removal in output (as required).
Input: nums = [9,9,9,9,9]
Output: 2
Explanation:
Remove first 3 elements → [9,9] Remove remaining 2 → [] Array becomes empty → all elements are now distinct.
Input: nums = [7,8,9]
Output: 2
Explanation:
All elements are already unique → no removal needed.
Accepted:
Submission: