Get Max Pairs
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's Get Max Pairs hit the OA circuit in April 2024, and candidates are blanking on whether it's a greedy problem or a pairing simulation. You've got an array or list, and you need to find the maximum number of pairs that satisfy some condition. The catch is that greedy doesn't always work here, and the naive O(n^2) approach will time out. StealthCoder is your safety net if the pairing logic locks you up during the live assessment.
Pattern and pitfall
Get Max Pairs is fundamentally a matching or pairing optimization problem. The typical structure is: given a collection of elements, find the maximum count of non-overlapping or disjoint pairs that meet a constraint (usually similarity, sum, or difference). Most candidates reach for greedy (sort and pair adjacent elements), which fails when elements can be paired in multiple ways. The real solution uses either sorting plus two-pointer validation, or a simulation loop that repeatedly extracts the best valid pair. The trick is recognizing that you must exhaust one element per pair and recompute eligibility each iteration. Off-by-one errors in pair removal and boundary checks are the main failure points. If you blank on the exact simulation state machine, StealthCoder reads the problem live and shows the iteration pattern immediately.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Get Max Pairs cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Get Max Pairs FAQ
Is this a greedy sort-and-pair problem?+
Not straightforward. Greedy works only if the optimal pair is always the locally best one. Amazon's version often requires simulation: find the best pair, remove both elements, repeat. Test greedy on the examples first. If a counterexample exists, switch to simulation.
What's the time complexity I should target?+
O(n^2) simulation is acceptable for most OA constraints (n less than 10k). If n is huge, sort and two-pointer with preprocessing (O(n log n)) might be necessary. The problem statement will hint at the size.
How do I track which elements are paired?+
Use a boolean array or set to mark used indices. After each pair extraction, mark both indices as used and skip them in the next iteration. This avoids modifying the original array and keeps logic clean.
What's the most common mistake on this problem?+
Removing elements from a list in a loop without careful index management, or greedily pairing without verifying that the pairing is globally optimal. Also forgetting to reset or revalidate eligibility after each pair.
How should I prepare in 24 hours if I haven't seen this before?+
Understand the constraint (what makes a valid pair). Code a brute-force simulation loop. Test on small examples. If time permits, think about whether sorting helps. The problem is more implementation discipline than algorithmic insight.