• + 9 comments

    We don't need to actually rotate the array. We can just use basic math to pull the entry from the original array:

            int shift = n - (k % n);
            int index = (shift + m ) % n;