Skip to content

Instantly share code, notes, and snippets.

@xcv58
Created May 27, 2017 03:37
Show Gist options
  • Save xcv58/ae2dea6331954c35d12ba16db3fb7279 to your computer and use it in GitHub Desktop.
Save xcv58/ae2dea6331954c35d12ba16db3fb7279 to your computer and use it in GitHub Desktop.
n = int(input())
prices = [int(i) for i in input().split()]
d = { x: i for i, x in enumerate(prices) }
sorted_prices = sorted(prices)
pairs = [ i - j for i, j in zip(sorted_prices[1:], sorted_prices[:-1]) if d[i] < d[j] ]
print(min(pairs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment