suggest me how to solve this problem

Ambiguous Permutations

  • its not that much difficult, small logic
  • scan till you reach n=0
  • for each test case let your array be 1-indexed(that is your array index starts from 1,2 and so on, that is a[1],a[2],…)
  • now traverse your array, check whether a[a[i]]=i or not
  • if it satisfies for every element of your array then your array is ambiguous
  • else it is not.
  • i hope you understand the logic if you face any difficulties comment below.
  • happy coding :slight_smile:

thanx i got it :slight_smile:

i got tle
please figre out where i am wrong
include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int A[100000],n,i;

while(1)
{
int flag=0;
cin>>n;
for(i=1;i<=n;i++)
cin>>A[i];
for(i=1;i<=n;i++){
if(A[A[i]]==i)
flag=1;
}
if(flag==1)
{
cout<<“ambiguous”<<endl;
}
else
{
cout<<“not ambiguous”<<endl;

}
}
return 0;

ohhh you are using while(1) and no break in your program so your program continues to run and hence leading to TLE.