Maximum Gap
A medium-tier problem at 49% community acceptance, tagged with Array, Sorting, Bucket Sort. Reported in interviews at DoorDash and 0 others.
Maximum Gap is the bucket sort problem that looks like a straightforward sorting question but has a hidden constraint that kills the obvious approach. You have to find the maximum difference between consecutive elements in a sorted array, but the naive sort-then-iterate solution won't pass the hard cases because the time complexity requirements force you away from comparison-based sorting. DoorDash has asked this, and it's a real filter. If you haven't seen bucket sort or radix sort before, this is where the pattern breaks you or builds you. StealthCoder runs invisibly during your OA and surfaces the bucket sort structure in seconds if you hit a wall on complexity.
Companies that ask "Maximum Gap"
Maximum Gap is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe trap is thinking you need to sort the input, which leads you straight to O(n log n), which fails the performance requirements. The actual insight is that the maximum gap must be larger than the minimum possible gap, calculated from the difference between max and min elements divided by the number of buckets. You bucket elements by value ranges, then scan buckets for the largest consecutive gap without ever fully sorting. Radix sort is the other route if you do sort, but bucket sort is cleaner here. Most candidates see 'gap' and 'sort' and lock onto comparison sorting. The trap is the constraints force you to linear or near-linear time. StealthCoder hedges this by showing you the bucket construction and gap logic when the obvious path fails during your live assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximum Gap recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Gap interview FAQ
Why can't I just sort and compare adjacent elements?+
You can in O(n log n), but the problem constraints demand better. The gap between min and max grows predictably with array size, so you can skip comparisons by bucketing by value range. Bucket sort or radix sort gets you to O(n) or O(n + k), which passes where comparison sorting fails.
Is this really asked at DoorDash and other companies?+
DoorDash has it on record. It's a medium-difficulty problem that filters for engineers who know sorting beyond quicksort and mergesort. It's less common than two-sum but comes up in rounds that test algorithmic depth over breadth.
What's the trick to finding the maximum gap without fully sorting?+
Calculate the minimum possible gap from (max - min) / (n - 1). Any gap smaller than that is between elements in the same bucket. The max gap must be between buckets, so you only track the min and max of each bucket and compare bucket boundaries. This skips internal comparisons entirely.
How do bucket sort and radix sort differ on this problem?+
Bucket sort divides by value range and finds gaps between bucket boundaries. Radix sort sorts all elements digit-by-digit in linear time, then you compare adjacent sorted elements. Bucket sort is more intuitive for this specific problem; radix sort is the brute force alternative if you can't see the bucketing pattern.
What's the acceptance rate and how hard is this really?+
Acceptance is around 49 percent. It's medium, but skewed hard because most candidates try the obvious sort-and-compare path and hit TLE. If you know the bucket insight beforehand, it's straightforward. Without it, you're rewriting at the last minute during the OA.
Want the actual problem statement? View "Maximum Gap" on LeetCode →