At Stripe, an engineering team tracks repeated workload sizes in a batch job and wants to reduce processing overhead. Given an integer array tasks, return the minimum number of operations needed to remove all tasks, where one operation can remove either 2 equal values or 3 equal values.
If it is impossible to remove all tasks under these rules, return -1.
tasks — a list of integers-1 if no valid sequence existsExample 1
tasks = [2, 3, 3, 2, 2, 4, 2, 3, 4]42 three times as one group of 3 and one group of 1 is not valid, so use counts: 2 -> 4 needs 2 operations, 3 -> 3 needs 1 operation, 4 -> 2 needs 1 operation. Total = 4.Example 2
tasks = [2, 1, 2, 2, 3, 3]-11 appears once, and a single task cannot be removed.1 <= len(tasks) <= 10^51 <= tasks[i] <= 10^9