mediumStringHash TableArrays & Hashing

Repeated DNA Sequences

mediumTime: O(n)Space: O(n)

Recognize the pattern

find 10-letter DNA sequences appearing more than oncesliding window + hash set

Brute force idea

Check every pair of 10-letter substrings — O(n²).

Better approach

Slide a window of size 10. Hash each window into a set. If already seen, it's a duplicate. O(n).

Key invariant

A hash set of seen substrings gives O(1) duplicate detection per window position.

Watch out for

Using two sets: 'seen' and 'result' — prevents adding the same duplicate to the result multiple times.

Arrays & Hashing Pattern