Reported January 2025
Amazongreedy

Optimal Interval Difference

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 Optimal Interval Difference landed in January 2025 assessments, and it's a greedy problem designed to catch candidates who optimize locally instead of globally. You have a set of intervals, and you need to pick some of them to maximize the difference between the largest and smallest values you select, subject to some constraint. The trick isn't the math. It's knowing when to stop being clever and just iterate through sorted choices. StealthCoder can surface the greedy choice in real time if you freeze on the logic.

Pattern and pitfall

The core insight: sort the intervals or the candidate values, then greedily pick endpoints that maximize spread. Most candidates overthink this as a dynamic-programming or scheduling problem, wasting 10-15 minutes. The greedy approach works here because once you've sorted, the maximum difference is always the largest minus the smallest from your eligible set, and you pick them in one pass without backtracking. Common pitfall is forgetting to check the constraint (whether intervals overlap, whether you're allowed to pick non-adjacent ones, etc.) before committing to a greedy strategy. The problem statement is light on details, which is typical of Amazon OA design. StealthCoder will help you parse the exact constraint and walk you through the greedy move if you blank mid-assessment.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Optimal Interval Difference 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Optimal Interval Difference FAQ

Is this really greedy, or is it a DP trap?+

It's greedy if the constraint allows you to pick the absolute max and min from your eligible set without loss. If it doesn't, you'll know immediately when you submit a wrong answer. Read the constraint twice before coding.

How do I know if intervals are overlapping?+

Sort by start time, then iterate. If the current interval's start is after or equal to the previous interval's end, there's no overlap. This is a standard interval merge problem pattern.

What's the time complexity I should aim for?+

O(n log n) for sorting plus O(n) for the greedy pass. That's optimal for interval problems. If you're considering anything exponential, you're overthinking.

Do I need to store all selected intervals, or just track min and max?+

Just track min and max values. The problem asks for the difference, not the intervals themselves. Don't build unnecessary data structures.

How much time should I spend understanding the constraint?+

As much as you need. The constraint is the entire problem. If you're unclear after 2-3 readings, ask for clarification or code a brute force first.

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