Problem
You get an integer array nums and an integer k. In one operation, you pick two items from nums with the sum k. Then you remove both items from the array.
Return the maximum number of operations that you can do.
Example 1
- Input:
- nums = [2,5,3,4,1,4], k = 6
- Output:
- 2
- Explanation:
- Remove 2 and 4, then remove 5 and 1. The items 3 and 4 remain, and their sum is not 6.
Example 2
- Input:
- nums = [3,3,3,3,3], k = 6
- Output:
- 2
- Explanation:
- Each operation removes two items with the value 3. One item remains.
Example 3
- Input:
- nums = [1,2,3], k = 10
- Output:
- 0
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
- 1 <= k <= 10^9
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
NVIDIA
Leetcode 1679. Max Number of K-Sum Pairs
Reported Jun 15, 2026 · 3 source reports
SENIOR
Source snapshot: Nov 12, 2026
View source