Determine whether an array can be split into pairs so that every element appears in exactly one pair of equal values.
Problem
Given an integer array nums, decide whether it is possible to partition the array into disjoint pairs such that both numbers in every pair are equal.
In other words, every element must be matched with exactly one other occurrence of the same value, and no element can be left unpaired.
Return true if such a partition exists, otherwise return false.
Notes
- Each pair must contain two equal values.
- Every array element must be used exactly once.
- The order of pairs does not matter.
Input Format
- An integer array
nums.
Output Format
- Return
trueif the array can be divided into equal-value pairs, otherwisefalse.
Constraints
1 <= nums.lengthnums.lengthis even- Values may repeat multiple times
Example 1
Input
nums = [3,2,3,2,2,2]
Output
true
Explanation
The array can be partitioned into pairs like (3,3), (2,2), and (2,2).
Example 2
Input
nums = [1,2,3,4]
Output
false
Explanation
Each value appears only once, so no equal pair can be formed.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.