[HackerRank][Python3] Minimum Loss
2018. 6. 5. 02:55 |
프로그래밍/HackerRank
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)
'프로그래밍 > HackerRank' 카테고리의 다른 글
| [HackerRank][Python3] Append and Delete (0) | 2018.06.10 |
|---|---|
| [HackerRank][Python3] Recursive Digit Sum (0) | 2018.06.07 |
| [HackerRank][Python3] Sam and substrings (0) | 2018.06.06 |
| [HackerRank][Python3] Marc's Cakewalk (0) | 2018.06.06 |
| [HackerRank][Python3] Strong Password (0) | 2018.06.05 |
| [HackerRank][Python3] Climbing the Leaderboard (0) | 2018.06.01 |
| [HackerRank][Python3] The Power Sum (1) | 2018.05.31 |
| [HackerRank][Python3] Construct the Array (0) | 2018.05.30 |
최근에 달린 댓글 최근에 달린 댓글