Quick actions

cmd+k|ctrl+k

Navigation

Languages

Untitled

Snippet info

Language

Python

Visibility

unlisted

Author

legacy-anonymous

Created

2021-11-26T14:09:32.713114Z

Updated

2021-11-26T14:09:32.713114Z

def ans(A):
    w = set() # walked
    res = 0 # result
    for a in A:
        c = 0 # count
        while a not in w:
            w.add(a)
            c += 1
            a = A[a]
        res = max(res, c)
    print(res)
#    0 1 2 3 4 5 6 7 8 9
ans([5,4,0,3,1,2])
ans([5,4,0,3,1,2,9,6,7,8])
INFO