mediumStringHash TableArrays & Hashing

Repeated DNA Sequences

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

Signals to notice

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

Brute force first

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

The key insight

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

What must stay true

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

Easy way to go wrong

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

Arrays & Hashing Pattern