Security Involution

  • + 0 comments

    js

    function processData(input) {
        //Enter your code here
        let arr = (input.split(`\n`)[1].split(' ').map(e => Number(e)))
        let c =0;
            
        let keys = [...arr.keys()]
        for(let key in  keys){
            if(arr.findIndex(n => n==(Number(key) +1))+1 == arr[Number(key)])
                c++;
        }
        if(Number(c)==arr.length )
            console.log("YES");
        else
            console.log("NO");
    }