Coding Trainer

Repeated DNA Sequences

MediumSliding Windowk-sliding-windowk-hash-map

Problem

Repeated DNA Sequences

The DNA sequence is composed of nucleotides 'A', 'C', 'G', and 'T'.

Given a string s representing a DNA sequence, return all 10-letter-long substrings that occur more than once. You may return the answer in any order.

Example 1:

Input:  s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
Output: ["AAAAACCCCC","CCCCCAAAAA"]

Example 2:

Input:  s = "AAAAAAAAAAAAA"
Output: ["AAAAAAAAAA"]

Constraints:

  • 1 <= s.length <= 10⁵
  • s[i] is 'A', 'C', 'G', or 'T'