• + 7 comments

    In your solution, you could use another modular arithmetic, to ensure the index stays within the boundaries of the array.

    queries.forEach(m => {
        // Modulo to stay inside the boundaries of the array
        console.log(arr[(n+m-k)%n]);
    });