Maximum Number of Pairs in Array

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 of size 2 where answer[0] is the number of pairs that are formed and answer[1] is the number of leftover integers in nums after doing the operation as many times as possible.

Example 1
Inputnums = [1,3,2,1,3,2,2]
Output[3,1]
A total of 3 pairs can be formed, leaving 1 number in nums.
Example 2
Inputnums = [1,1]
Output[1,0]
The two equal numbers form 1 pair, leaving 0 numbers in nums.

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 100

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate