Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Max Number of K-Sum Pairs

XPChallenge Points: 20
levelLevel: Medium

You are given an array of integers and a number k.
In one move, you can choose any two numbers from the array whose sum equals k, and then remove those two numbers from the array.

Your task is to count how many such removal operations can be performed in total until no more valid pairs remain.

Example 1:

Input: nums = [2, 8, 4, 6, 10], k = 12

Output: 2

Explanation:

Remove (2, 10) → remaining: [8, 4, 6] Remove (8, 4) → remaining: [6] No more pairs.

Example 2:

Input: nums = [5, 5, 5, 5], k = 10

Output: 2

Explanation:

Pairs: (5, 5), (5, 5)

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result