This one is from HackerRank, and is a conceptually pretty simple. The trick here is not to get tangled up while implementing “circular array filling”, and it took me a while to get rid of all bugs.


The trick here is to construct an array for every “square” you see on the picture. Then simply rotate each of the “squares” desired number of times, and then reconstruct the original multiline string to submit the result.