Problem statement

https://binarysearch.com/problems/Recurring-Character/

Solution

Just iterate and find first repetition using set.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, s):
        d = set()
        for i, x in enumerate(s):
            if x not in d:
                d.add(x)
            else:
                return i
        return -1