• + 0 comments

    function circularArrayRotation(a, k, queries) {

        let x = k % a.length;
        let result = [];
        for(let i = 0; i < queries.length; i++) {
            // the formal is (queries[i] + a.length - x) % a.length to get the right index after rotation 
            result.push(a[(queries[i] + a.length - x) % a.length]);
        }
        return result;
    

    }