<p>Given an integer array <code>nums</code>, return <em>the maximum difference between two successive elements in its sorted form</em>. If the array contains less than two elements, return <code>0</code>.</p>

<p>You must write an algorithm that runs in linear time and uses linear extra space.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,6,9,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [10]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The array contains less than 2 elements, therefore return 0.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

import math

class Solution:
    def maximumGap(self, nums: List[int]) -> int:
        n = len(nums)
        if n < 2: return 0
        max_num, min_num = 0, float("inf")
        for num in nums:
            max_num = max(max_num, num)
            min_num = min(min_num, num)
        
        gap = math.ceil((max_num - min_num) / (n - 1))
        if gap == 0: return 0
        buckets = [[None, None] for _ in range(n)]
        for num in nums:
            i = (num - min_num) // gap
            print(i)
            if not buckets[i][0] or num < buckets[i][0]:
                buckets[i][0] = num
            if not buckets[i][1] or num > buckets[i][1]:
                buckets[i][1] = num

        diff = 0
        for i in range(1, len(buckets)):
            prev_max = buckets[i-1][1]
            if not prev_max: continue
            cur_min = buckets[i][0]
            if not cur_min:
                buckets[i][1] = prev_max
                continue
            cur_diff = cur_min - prev_max
            diff = max(diff, cur_diff)
        
        return diff
32713