Max Number of K-Sum Pairs
You are given an integer array nums and an integer k.
In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.
Return the maximum number of operations you can perform on the array.
Example 1
Input
nums = [1,2,3,4], k = 5Output
2The pairs (1, 4) and (2, 3) each sum to 5, so 2 operations can be performed.
Example 2
Input
nums = [3,1,3,4,3], k = 6Output
1Only one pair of 3's can be removed to sum to 6, so 1 operation can be performed.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
- 1 <= k <= 10^9