[HackerRank][Python3] Minimum Distances
2018. 9. 6. 20:58 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/minimum-distances/problem
My Solution :
#!/usr/bin/env python3 def minimum_distances(a): min_d = float('inf') last_index = {} for i, num in enumerate(a): if num in last_index: min_d = min(min_d, i-last_index[num]) last_index[num] = i return min_d if min_d != float('inf') else -1 n = int(input()) a = list(map(int, input().rstrip().split())) result = minimum_distances(a) print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Fair Rations (0) | 2018.09.07 |
---|---|
[HackerRank][Python3] Flatland Space Stations (0) | 2018.09.06 |
[HackerRank][Python3] Lisa's Workbook (0) | 2018.09.06 |
[HackerRank][Python3] Halloween Sale (0) | 2018.09.06 |
[HackerRank][Python3] Beautiful Triplets (0) | 2018.09.06 |
[HackerRank][Python3] Equalize the Array (0) | 2018.09.06 |
[HackerRank][Python3] Jumping on the Clouds (0) | 2018.09.06 |
[HackerRank][Python3] Sequence Equation (0) | 2018.09.05 |
최근에 달린 댓글 최근에 달린 댓글