Minimum Connected Delivery Zones After Adding One Interval
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's asking you to merge overlapping delivery zones and minimize fragments when you add one new interval. You get an array of existing zones, add a new one, and count how many separate connected regions remain. It's a classic interval merge problem with a twist: you're not just merging, you're optimizing placement. If you've done interval scheduling or seen merge-interval patterns before, the core idea will click. StealthCoder can spot the merge logic in seconds if you freeze up on the live OA.
Pattern and pitfall
The trick is understanding that merging intervals reduces fragmentation. You sort all intervals, merge overlapping ones, then add the new interval optimally to minimize the final count. Most candidates jump to greedy placement without thinking through the merge step first. The pattern: sort by start time, iterate through with a running merge window, track when intervals don't overlap (that's a new zone). When you add the new interval, you need to figure out where it fits to maximize overlap with existing zones. This is less about complex data structures and more about getting the merge logic right. StealthCoder can feed you the interval-merge template instantly if you blank on the exact merge condition during the assessment.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Minimum Connected Delivery Zones After Adding One Interval 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 by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as merge intervals. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Connected Delivery Zones After Adding One Interval FAQ
Is this just interval merge with extra steps?+
Basically, yes. Standard merge-intervals pattern, then you optimize one new interval placement. The twist is the optimization part: you're not just merging what's given, you're choosing where to add a new one to keep the count low.
Do I need to try all possible positions for the new interval?+
Not all positions. The optimal placement overlaps with at least one existing zone or fills a gap between two. Think about where it does maximum merging. Sort first, then scan linearly to find the best insertion.
What if the new interval covers everything?+
Then all zones merge into one. That's the minimum possible count. The edge case is when one interval subsumes all others, or when the new interval spans the entire range.
How hard is this compared to standard interval problems?+
Medium. Standard merge-intervals is easy once you get the two-pointer or stack approach. This adds the 'where to place new' decision. If you know merge-intervals cold, you're 70 percent there.
Should I implement a full brute-force or jump to optimized?+
Sort and merge first. That's O(n log n). Then iterate once to find optimal placement for the new interval. Brute-force positioning is slow. The one-pass greedy placement after sorting is the expected path.