Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Divide Array Into Equal Pairs

XPChallenge Points: 10
levelLevel: Easy

You are given an array nums containing 2 * n integers. Your goal is to split the array into n pairs where:

  • Each number appears in exactly one pair.

  • Both values in every pair must be identical.

Return true if such a pairing is possible. Otherwise, return false.

Example 1:

Input: nums = [5,5,7,7,7,7]

Output: true

Explanation:

We have 6 elements → need 3 pairs. Possible pairs: (5,5), (7,7), (7,7) Each pair contains equal values, so pairing is valid.

Example 2:

Input: nums = [4,1,4,2]

Output: false

Explanation:

We need two pairs, but there is only one '1' and one '2', so they cannot form pairs of equal values.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result