Max Number of K-Sum Pairs
A medium-tier problem at 56% community acceptance, tagged with Array, Hash Table, Two Pointers. Reported in interviews at DE Shaw and 1 others.
Max Number of K-Sum Pairs sits at the intersection of constraint satisfaction and greedy optimization, and it shows up in real assessments. DE Shaw and Yandex have both asked it. The problem is deceptively simple on the surface: given an array and a target sum, maximize how many pairs you can remove where each pair sums to that target. Most candidates either brute-force or miss the greedy insight entirely. Your acceptance rate is 56%, meaning half the room gets stuck on either the pairing logic or the efficiency requirement. If this hits your live OA and you freeze on whether to sort, hash, or pointer-walk, StealthCoder runs invisibly and surfaces a working solution in seconds.
Companies that ask "Max Number of K-Sum Pairs"
Max Number of K-Sum Pairs is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.
Get StealthCoderThe trap is thinking you need to find all pairs first, then count them. You don't. The key is greedy: maximize count by processing the array in a way that never wastes a valid pair. Two pointers after sorting is the classic move: sort, then walk inward from both ends. If the sum is too small, move left pointer right. If too large, move right pointer left. If exact, count it and advance both. Hash table is the alternative if you want to avoid sorting: count frequencies, iterate the array once, and decrement both elements from a pair's frequency simultaneously. The gap between brute force (quadratic) and either solution (linear to O(n log n)) is where interviews separate. Most struggle with the frequency-based approach when duplicates exist. StealthCoder covers both paths and handles edge cases like single-element pairs and ties, so if the greedy pattern doesn't click during the real assessment, you're covered.
Pattern tags
You know the problem.
Make sure you actually pass it.
Max Number of K-Sum Pairs recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Max Number of K-Sum Pairs interview FAQ
Is this a hard problem or do I just feel bad about it?+
It's a medium, but 44% of submissions fail. You're not alone. The problem feels like it should be simpler than it is because the statement is short. The trick is recognizing that greedy (maximize pairs on first pass) beats exhaustive search. Once you see that, it clicks fast.
Which approach is faster: sorting and two pointers or hash table?+
Hash table is O(n) time and O(n) space, sorting is O(n log n) time and O(1) extra space. In an interview, hash table usually feels more intuitive for pair problems, but both are acceptable. Pick whichever you code faster under pressure.
Do DE Shaw and Yandex really ask this, or is the data stale?+
Both companies are in the confirmed ask list for this problem. Reports aren't time-stamped, so assume recent if you're interviewing there. Mid-level candidates at these firms definitely encounter pairing and constraint problems.
What's the biggest gotcha on this problem?+
Forgetting to handle duplicates correctly. If the array has [1, 1, 1, 1] and target is 2, you can make two pairs, not one. Hash table approach forces you to think about frequency. Sorting makes it obvious: paired elements are consumed.
Should I memorize this or understand the pattern?+
Understand the pattern: greedy pairing + two pointers or frequency map. This pattern repeats across container-with-most-water, valid-palindrome, and other medium problems. Drill the pattern once, and you handle a dozen variants.
Want the actual problem statement? View "Max Number of K-Sum Pairs" on LeetCode →