2421. Maximum Number of Pairs in Array
My accepted JavaScript solution to LeetCode problem 2421, Maximum Number of Pairs in Array, running in 0ms.
- Difficulty: Easy
- JavaScript
- Runtime 0ms
- Memory 54.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 0ms, memory 54.2MB, accepted 2025-12-29.
var numberOfPairs = function(nums) {
const count = new Map();
for (const num of nums) {
count.set(num, (count.get(num) || 0) + 1);
}
let pairs = 0, leftover = 0;
for (const c of count.values()) {
pairs += Math.floor(c / 2);
leftover += c % 2;
}
return [pairs, leftover];
};