#3396

Minimum Number of Operations to Make Elements in Array Distinct

newbie · 275 · lc easy +19 · 71.3% accepted · 563 likes · top 80%

Description

You are given an integer array nums. To ensure all elements are distinct, you may apply the following operation any number of times:

- Remove the first 3 elements from nums. If fewer than 3 remain, remove all remaining elements.

An empty array is considered to have distinct elements. Return the minimum number of operations needed to make all elements of nums distinct.

Code

1
2
3