For the problem Repeated DNA Sequences: Solution: Repeated DNA Sequences
The optimized solution’s worst case runtime is:
To handle this case, I think we could create a third hash set to track which substrings we’ve already added to our result set, to prevent repeatedly creating and adding the same substring to the result set.
To demonstrate a worst case that we can’t navigate, we could maybe use an example like this: K=4, S=[1111 1111 1112 1112 1121 1121 1211 1211…] where the number of results is proportional to the length of the input.