Skip to content

Instantly share code, notes, and snippets.

@rishi93
Last active March 24, 2016 06:11
Show Gist options
  • Select an option

  • Save rishi93/24d8073258400a244dbe to your computer and use it in GitHub Desktop.

Select an option

Save rishi93/24d8073258400a244dbe to your computer and use it in GitHub Desktop.
Ambiguous Permutations - PERMUT2
def ifAmbiguous(arr,length):
for i in range(0,length):
num = i + 1
pos = arr[i] - 1
if arr[pos] != num:
return False
return True
while True:
length = int(input())
if length == 0:
break
arr = [int(x) for x in input().split()]
if(ifAmbiguous(arr,length)):
print("ambiguous")
else:
print("not ambiguous")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment