Repeated DNA Sequences
The DNA string s consists of the characters 'A', 'C', 'G', and 'T'. Return all 10-letter-long substrings that occur more than once in s. You may return the answer in any order.
Open official problem prompt ↗Report every distinct 10-character DNA sequence that appears at least twice anywhere in the string.
Like scanning a long text with a fixed 10-character viewfinder, jotting each snippet on a 'seen' list; the moment a snippet reappears you copy it to a 'duplicates' list, and the duplicates list ignores repeats of repeats.
- Input
- s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
- Output
- ["AAAAACCCCC", "CCCCCAAAAA"]
- Why
- The 10-letter windows 'AAAAACCCCC' and 'CCCCCAAAAA' each appear at two different starting positions; no other 10-mer repeats.
1 <= s.length <= 10^5s[i] is either 'A', 'C', 'G', or 'T'