I am encountering a problem in practice questions(EASY)-Ambiguous Permutations.It says Runtime Error(SIGSEGV),even though it runs fine for all cases on my computer.Here is the code.
#include<stdio.h>
int main()
{
int n = -1,i;
while(n!=0)
{
int flag = 0;
scanf("%d",&n);
if(n==0)
{
break;
}
int a[10000];
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
if(a[a[i]]!=i)
{
flag++;
}
}
if(flag!=0)
{
printf("\nnot ambigious\n");
}
else
{
printf("\nambigious\n");
}
}
return 0;
}
Please help.