Count the maximum number of disjoint pairs whose sum equals a target value k.
You are given an integer array nums and an integer k.
In one operation, you may choose two different elements from nums whose sum is exactly k, then remove both elements from the array.
Return the maximum number of operations you can perform.
The same element cannot be used in more than one operation.
numskk.Example 1
Input
nums = [1,2,3,4], k = 5
Output
2
Explanation
The pairs (1,4) and (2,3) both sum to 5, so we can perform 2 operations.
Example 2
Input
nums = [3,1,3,4,3], k = 6
Output
1
Explanation
Only one pair can be formed: (3,3). After using those two 3s, no other valid pair remains.
Example 3
Input
nums = [2,5,4,1,3,3], k = 6
Output
2
Explanation
One valid pairing is (2,4) and (3,3), giving 2 operations.
Premium problem context
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.