You are viewing a single comment's thread. Return to all comments →
Python 3, First check if its Bijective, then match the two functions
n = int(input()) Y = [int(x) for x in input().split()] F = {key+1:val for key,val in enumerate(Y)} F_Inverse = {val:key for key,val in F.items()}
if len(set(Y)) != len(Y): print('NO') else: if F == F_Inverse: print('YES') else: print('NO')
Security Involution
You are viewing a single comment's thread. Return to all comments →
Python 3, First check if its Bijective, then match the two functions
n = int(input()) Y = [int(x) for x in input().split()] F = {key+1:val for key,val in enumerate(Y)} F_Inverse = {val:key for key,val in F.items()}
if len(set(Y)) != len(Y): print('NO') else: if F == F_Inverse: print('YES') else: print('NO')