Skip to content

Instantly share code, notes, and snippets.

@mdpabel
Created April 3, 2022 09:33
Show Gist options
  • Save mdpabel/bde19baaa2b8eec8ad549033539b5a07 to your computer and use it in GitHub Desktop.
Save mdpabel/bde19baaa2b8eec8ad549033539b5a07 to your computer and use it in GitHub Desktop.
class Solution:
# @param A : tuple of integers
# @return an integer
def maximumGap(self, A):
n = len(A)
nums = []
for item in enumerate(A):
nums.append(item)
def cmp(a):
return a[1]
nums.sort(key=cmp)
max_distance = 0
min_num = nums[0][0]
for num in nums:
if num[0] <= min_num:
min_num = num[0]
else:
max_distance = max(max_distance, num[0] - min_num)
return max_distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment