app.codility.com/programmers/lessons/4-counting_elements/frog_river_one/
FrogRiverOne coding task - Learn to Code - Codility
Find the earliest time when a frog can jump to the other side of a river.
app.codility.com
# 1~X 위치가 모두 나타나는 최초 시간
def solution(X, A):
S = set(range(1, X + 1))
N = len(A)
for i in range(N):
if A[i] in S:
S.remove(A[i])
if len(S) == 0:
return i
return -1
print(solution(5, [1, 3, 1, 4, 2, 3, 5, 4])) # 6
print(solution(2, [2, 2, 2, 2, 2])) # -1
'Codility' 카테고리의 다른 글
[Lesson 6][Sorting] Distinct (0) | 2021.05.07 |
---|---|
[Lesson 5][Prefix Sums] CountDiv (0) | 2021.05.07 |
[Lesson 3][Time Complexity] FrogJmp (0) | 2021.05.07 |
[Lesson 2][Arrays] CyclicRotation (0) | 2021.05.07 |
[Lesson 1][Iterations] BinaryGap (0) | 2021.05.07 |