Rotate the string in O(n) time and O(1) space

An animated algorithm, with 0 lines of code

Let’s consider a classic algorithmic problem — string rotation. Given a string and offset, we should return the rotated string. That is for “Matrix” and offset equal to two the result would be “ixMatr”: