find the first repeated character in a string without using extra space with extra space its simple just check for the element in a hash map if present then it is the recurrent char without extra space idea the idea is to use an integer variable and uses bits in its binary representation to store whether a character is present or not typically an integer has atleast 32 bits and we need to store presenceabsence of only 26 characters find the first repeated character in a string without using extra space with extra space its simple just check for the element in a hash map if present then it is the recurrent char without extra space idea the idea is to use an integer variable and uses bits in its binary representation to store whether a character is present or not typically an integer has at least 32 bits and we need to store presence absence of only 26 characters
def first_recurrence(s):
    checker = 0 
    pos = 0
    for i in s:
        val = ord(i) - ord('a')
        if (checker & (1 << val) > 0):
            return i
        checker = checker | (1 << val)
        pos += 1
    return -1