I read of a job interview question to write some code for the following:
Write an efficient function to find the first nonrepeated character in a st
# I came up with another solution but not efficient comment?
str1 = "awbkkzafrocfbvwcqbb"
list1 = []
count = 0
newlen = len(str1)
find = False
def myfun(count, str1, list1, newlen):
for i in range(count, newlen):
if i == 0:
list1.append(str1[i])
else:
if str1[i] in list1:
str1 = str1.translate({ord(str1[i]): None})
print(str1)
newlen = len(str1)
count =0
i = count
list1.pop()
myfun(count,str1,list1,newlen)
else:
pass
if str1.find(list1[0], 1, len(str1)) != -1 :
pass
else:
print(list1[0]+" is your first non repeating character")
exit()
myfun(count, str1, list1, newlen)