Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Logic for " Ambiguous Permutations "

$
0
0

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


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>