Ambiguous permutation

My code passes the test cases then also it shows WA , WHY?

#include<bits/stdc++.h>
using namespace std;
int main()
{
long int num;
cin>>num;
while(num!=0)
{
long int arr[num];
long int array[num];

    for(int i=1;i<=num;i++)
        {
            cin>>arr[i];
        }
    
    for(int i=1;i<=num;i++)
        {
            array[arr[i]]=i;
        }
    
    for(int i=1;i<=num;i++)
        {
        if(arr[i]==array[i])
            {
            cout<<"ambiguous"<<endl;
            break;   
            }
        else
            {
            cout<<"not ambiguous"<<endl;    
            break;
            }
        }    
    cin>>num;
}

}

where is the question?

1 Like

Problem

what you see is sample test case but when you submit your code then it runs on other hidden test cases which is not visible.

1 Like

What to do now?
I myself tests all cases.

yes you just try some random test cases and always remember to check corner test cases.

1 Like

there is 1 error in your code
if(arr[1]==array[1]) that does not mean it will be ambiguous you have to check it for whole array but you have applied break there
i have modified yur code
https://www.codechef.com/viewsolution/34836818

1 Like

Thanks