Problem statement

https://binarysearch.com/problems/Index-Into-an-Infinite-String/

Solution

Just use % functionality here.

Complexity

It is O(j - i) for time and space.

Code

class Solution:
    def solve(self, s, i, j):
        n = len(s)
        return "".join(s[x%n] for x in range(i, j))