Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make Array Empty

Minimum Number of Operations to Make Array Empty asks you to remove every array element in groups of two or three equal values, using as few operations as possible, or return negative one if impossible.

Statement

You are given a 00 indexed array nums consisting of positive integers.

You can perform two types of operations on the array any number of times:

  • Choose 22 elements with equal values and remove them from the array.

  • Choose 33 elements with equal values and remove them from the array.

Return the minimum number of operations required to make the array empty, or −1-1 if it is impossible to empty the array.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make Array Empty

Minimum Number of Operations to Make Array Empty asks you to remove every array element in groups of two or three equal values, using as few operations as possible, or return negative one if impossible.

Statement

You are given a 00 indexed array nums consisting of positive integers.

You can perform two types of operations on the array any number of times:

  • Choose 22 elements with equal values and remove them from the array.

  • Choose 33 elements with equal values and remove them from the array.

Return the minimum number of operations required to make the array empty, or −1-1 if it is impossible to empty the array.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6