Reported April 2025
Amazongreedy

Optimal Utilization

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 asked this in April 2025, and it's a greedy problem that looks deceptively simple on first read. You get two lists of integers (usually device weights or costs) and need to find the pair with the maximum sum that doesn't exceed a given limit. The trick is understanding why a greedy two-pointer sweep works here, not a brute force nested loop. If you blank on the approach during the OA, StealthCoder will surface the pattern instantly so you can code with confidence.

Pattern and pitfall

The core insight is that if you sort both arrays, you can use two pointers: one starting at the end of the first array (largest value) and one at the start of the second (smallest value). Move the pointers inward based on whether the current sum exceeds the limit. This greedy approach guarantees you find the maximum valid sum in O(n log n) time, much faster than checking all pairs. Most candidates default to nested loops and time out. The gotcha is handling ties correctly and making sure you actually track the best pair seen so far, not just the final state of the pointers.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Optimal Utilization 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Optimal Utilization FAQ

What's the actual trick Amazon is testing here?+

They want to see if you recognize that sorting plus two pointers beats brute force. The greedy choice (always try the largest values first, then shrink the search space) works because the arrays are independent. It's about pattern recognition, not complex DP.

Do I need to return the indices or the values themselves?+

Almost always the indices from the original unsorted arrays. That's why you need to either map back or preserve original indices during sorting. This is where candidates typically drop points.

What if there are multiple pairs with the same maximum sum?+

Return any one of them. Amazon's test cases usually have a unique maximum, but check the exact problem statement. If not, pick the first valid pair your two-pointer pass finds.

Can I just brute force all pairs and filter?+

Yes, it will work for small inputs (n < 1000). But Amazon's OAs often have hidden large test cases. Brute force O(n^2) will time out. Greedy two-pointer is the expected solution.

How do I prepare for this in 48 hours?+

Understand why two-pointer works: once sorted, moving left from high end and right from low end explores the optimal space. Code it twice. Test on edge cases: empty arrays, no valid pair, limit is very tight. Then trust the pattern.

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