0% found this document useful (0 votes)
2 views

LeetCode - The World's Leading Online Programming Learning Platform 2

Uploaded by

Jyda MatSoch
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

LeetCode - The World's Leading Online Programming Learning Platform 2

Uploaded by

Jyda MatSoch
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Daily Question Premium Register or Sign in

Description Editorial Solutions (2.4K) Submissions C++ Auto

Companies 1 class Solution {


2 public:
You are given a 0-indexed array nums consisting of positive integers. 3 int minOperations(vector<int>& nums) {
4
There are two types of operations that you can apply on the array any number of times:
5 }
6 };
Choose two elements with equal values and delete them from the array.

Choose three elements with equal values and delete them from the array.

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

Example 1:

Input: nums = [2,3,3,2,2,4,2,3,4]


Output: 4
Explanation: We can apply the following operations to make the array empty:
- Apply the first operation on the elements at indices 0 and 3. The resulting
array is nums = [3,3,2,4,2,3,4].
- Apply the first operation on the elements at indices 2 and 4. The resulting
array is nums = [3,3,4,3,4].
- Apply the second operation on the elements at indices 0, 1, and 3. The
resulting array is nums = [4,4].
- Apply the first operation on the elements at indices 0 and 1. The resulting
array is nums = [].
It can be shown that we cannot make the array empty in less than 4
operations.

Example 2: Saved to local Ln 6, Col 3

Input: nums = [2,1,2,2,3,3] You need to Login / Sign up to run or submit


Output: -1
Explanation: It is impossible to empty the array.
Console Run Submit

You might also like