Reported November 2024
Amazongreedy

Get Max Discount Pairs

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon's November OA hit you with a pairing problem, and you've got maybe 48 hours to lock in the pattern. Get Max Discount Pairs is asking you to match items optimally, likely to maximize some discount value or minimize cost. This is a classic greedy or dynamic-programming setup that hinges on sorting first and then either pairing greedily or checking all valid combinations. StealthCoder sits invisible on your screen during the live assessment, ready to catch you if the sorting trick or the pairing logic slips your mind under pressure.

Pattern and pitfall

The problem almost certainly wants you to pair array elements to maximize discount (or minimize total). The trick is usually: sort first, then either pair adjacent elements greedily, or use two pointers to match highest with lowest. Common pitfall is trying to brute-force all pairings without sorting, which explodes time complexity. If the discount formula is nonlinear (e.g., min of pair, or sum of pair times count), you need to test whether greedy (pair adjacent after sort) or two-pointer (pair extremes) wins. Some versions ask for max pairs under a threshold, which flips to a different greedy or binary-search approach. The pattern is almost always sorting plus greedy or two-pointer selection. StealthCoder gives you the confidence to commit to the sort-and-pair skeleton without second-guessing under the timer.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Get Max Discount 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 StealthCoder

Related leaked OAs

⏵ The honest play

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 Discount Pairs FAQ

Is this a sorting + greedy problem or DP?+

Almost certainly sorting plus greedy pairing. Sort the array, then decide: pair adjacent elements, or use two pointers to match high with low. DP would be overkill unless the discount formula is cumulative and order matters across pairs. Test the greedy approach first.

What's the most common pitfall candidates hit?+

Forgetting to sort before pairing, or not recognizing that pairing adjacent elements after sort is optimal. Also: miscalculating the discount formula. Read the exact discount rule twice. It changes everything.

Do I need to return pairs or just the max discount value?+

The problem probably asks for max discount (a single number), not the pairs themselves. But reread the output spec on the OA. If it's ambiguous, code for the number first, then output the pairs as a second step if needed.

What if the array is unsorted and has duplicates?+

Duplicates don't break sorting. Just sort and proceed. The greedy approach (pair adjacent after sort) still works because you're capturing the best local pairings, which sum to the global optimum under typical discount formulas.

How fast should my solution run?+

Sorting is O(n log n), pairing is O(n). Target O(n log n) total. If you're doing nested loops or backtracking, you're overthinking it. Go back to sort plus two-pointer or adjacent pairing.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it