**Physical Address**

304 North Cardinal St.

Dorchester Center, MA 02124

You are given a **0-indexed** integer array `nums`

. In one operation, you may do the following:

- Choose
**two**integers in`nums`

that are**equal**. - Remove both integers from
`nums`

, forming a**pair**.

The operation is done on `nums`

as many times as possible.

Return *a 0-indexed integer array *

`answer`

`2`

`answer[0]`

`answer[1]`

`nums`

**Example 1:**

```
Input: nums = [1,3,2,1,3,2,2]
Output: [3,1]
Explanation:
Form a pair with nums[0] and nums[3] and remove them from nums. Now, nums = [3,2,3,2,2].
Form a pair with nums[0] and nums[2] and remove them from nums. Now, nums = [2,2,2].
Form a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [2].
No more pairs can be formed. A total of 3 pairs have been formed, and there is 1 number leftover in nums.
```

**Example 2:**

```
Input: nums = [1,1]
Output: [1,0]
Explanation: Form a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [].
No more pairs can be formed. A total of 1 pair has been formed, and there are 0 numbers leftover in nums.
```

**Example 3:**

```
Input: nums = [0]
Output: [0,1]
Explanation: No pairs can be formed, and there is 1 number leftover in nums.
```

**Constraints:**

`1 <= nums.length <= 100`

`0 <= nums[i] <= 100`

```
vector<int> numberOfPairs(vector<int>& nums) {
int cnt[101]{};
for(auto i:nums) cnt[i]++;
int pairs=0, leftover=0;
for(int i:cnt){
pairs+= i/2;
leftover+= i%2;
}
return {pairs,leftover};
}
```

```
public int[] numberOfPairs(int[] nums) {
int cnt[]= new int[101];
for(int i:nums) cnt[i]++;
int pairs=0, leftover=0;
for(int i:cnt){
pairs+= i/2;
leftover+= i%2;
}
return new int[]{pairs,leftover};
}
```

```
class Solution:
def numberOfPairs(self, nums: List[int]) -> List[int]:
ans = [0] * 2
c = Counter(nums)
for v in c.values():
ans[0] += (v // 2)
ans[1] += (v % 2)
return ans
```

In our experience, we suggest you solve this Maximum Number of Pairs in Array LeetCode Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Maximum Number of Pairs in Array LeetCode Solution

I hope this Maximum Number of Pairs in Array LeetCode Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

**More Coding Solutions >>**