프로그래밍/HackerRank
[HackerRank][Python3] Minimum Loss
snoopybox
2018. 6. 5. 02:55
Problem :
https://www.hackerrank.com/challenges/minimum-loss/problem
My Solution :
#!/usr/bin/env python3 def minimumLoss(n, price): ret = 10**16 a = [(price[i], i) for i in range(n)] a = sorted(a, reverse=True) for i in range(n-1): if a[i][0] - a[i+1][0] < ret and a[i][1] < a[i+1][1]: ret = a[i][0] - a[i+1][0] return ret n = int(input()) price = list(map(int, input().strip().split())) result = minimumLoss(n, price) print(result)