For the problem Ambiguous Permutations I read in one of the posted solutions the following piece of code which executes very fast :
boolean check=true;
int loc=0;
for(int i=0;i<array.length;i++){
loc=array[i];
if (array[loc-1]!=i+1){
check=false;
break;
}
}
Can someone please explain me how to reach this expression mathematically ? How to derive this ? I couldn't figure out how the relation was obtained / the steps for it