Created
May 27, 2017 03:37
-
-
Save xcv58/ae2dea6331954c35d12ba16db3fb7279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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