You are viewing a single comment's thread. Return to all comments →
This code may give index out of bound error if value exceed the higher index. I have made few changes.
n = input() x = map(int, raw_input().split()) for i in range(0,n): try : if i+1 != x[x[i]-1]: print "NO" exit(0) except IndexError: print "NO" exit(0) print 'YES'
Seems like cookies are disabled on this browser, please enable them to open this website
Security Involution
You are viewing a single comment's thread. Return to all comments →
This code may give index out of bound error if value exceed the higher index. I have made few changes.