Maximum Number of Pairs in Array Problem

Maximum Number of Pairs in Array Problem — ExecCode Easy DSA Practice

Solve the Maximum Number of Pairs in Array problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a 0-indexed integer array nums. Your task is to compute the required answer and 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. 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.

Examples

Input {"nums": [1, 3, 2, 1, 3, 2, 2]}; Output [3, 1]. Input {"nums": [1, 1]}; Output [1, 0]

Constraints

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

Practice Maximum Number of Pairs in Array free on ExecCode. Browse DSA problems, topic map, and placement guides.