Skip to main content
Back to problems
Leetcode
Easy
Arrays
Hash Maps
Math
Divide Array Into Equal Pairs

Determine whether an array can be split into pairs so that every element appears in exactly one pair of equal values.

Acceptance 0%
Problem Statement

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 true if the array can be divided into equal-value pairs, otherwise false.

Constraints

  • 1 <= nums.length
  • nums.length is even
  • Values may repeat multiple times
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.