15 lines
415 B
Python
15 lines
415 B
Python
def solution(cards):
|
|
cycle_length = [0, 0]
|
|
group = [-1] * len(cards)
|
|
for i in range(len(cards)):
|
|
if group[i] != -1:
|
|
continue
|
|
curr = i
|
|
count = 0
|
|
while group[curr] == -1:
|
|
group[curr] = i
|
|
curr = cards[curr] - 1
|
|
count += 1
|
|
cycle_length = sorted(cycle_length + [count])[-2:]
|
|
return cycle_length[0] * cycle_length[1]
|