###########################################################################
#                                                                         #
# Author: Daniel Mock                                                     #
#                                                                         #
# Purpose: To document progress in learning algorithms & data structures  #
#                                                                         #
# References: This question was generated by leetcode.com. The solution   #
# to the question was generated by Daniel Mock.                           #
#                                                                         #
###########################################################################


'''
This is an iterative approach that checks all 10-character long substrings within the orignal string starting with the first character and moves towards the end of the string.
EX: string s = 'abcdefghijabcdefghijz'
	1st substring: [abcdefghij]
		- insert into dictionary & check for duplicate
	2nd substring: [bcdefghija]
		-insert into dictionary & check for duplicate
	3rd substring: [cdefghijab]
		- insert into dictionary & check for duplicate
	...
	11th substring: [abcdefghij]
		- detects duplicate, adds to output list and increments value in dictionary so not used again
	12th substring: [bcdefghijz]
		-  insert into dictionary & check for duplicate
	Since the length of thenext substring, 'cdefghijz' is only 9 characters, it returns the list of duplicates
'''

from collections import defaultdict
class Solution:
    def findRepeatedDnaSequences(self, s: str) -> List[str]:
        if s is None: return
        output_list = []
        string_dict = defaultdict(int)
        for index, letter in enumerate(s):
            if index+10<=len(s):
                if string_dict[s[index:index+10]] == 1:
                    output_list.append(s[index:index+10])
                    string_dict[s[index:index+10]] +=1
                elif string_dict[s[index:index+10]] > 1:
                    continue
                else: string_dict[s[index:index+10]] = 1

            else: return output_list
