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.
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":5}
Output: 2
Constraints:
1≤nums.length≤105
1≤nums[i]≤109
1≤k≤109
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,2,3,4],"k":5}
Find as many disjoint pairs as possible that add up to k = 5. First, sort the numbers.