Maximum gap linear time
Given an unsorted integer array `nums`, return the maximum difference between two successive elements once the array is sorted. If the array has fewer than two elements, return 0. You must run in linear time and use linear extra space — so use bucket sort / the pigeonhole principle (the max gap is at least ceil((max-min)/(n-1)), so it must occur across bucket boundaries), NOT a comparison sort.
Implement
maximum_gap(nums: list[int]) → intExamples
in
[[3,6,9,1]]out3What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 30 min
solution.py
InputExpectedGot
[[3,6,9,1]]3not run yetsample