Repeated DNA Sequences

Medium Topics Company Tags

Find every distinct substring of length exactly 10 that occurs at least twice in the DNA string s. The alphabet is A, C, G, and T. Occurrences may overlap. Return each repeated substring once, in any order. If no length-10 substring repeats, return an empty array.

Example 1:

Input: s = "CCCCCCCCCCCC"

Output: ["CCCCCCCCCC"]

Explanation: The substring CCCCCCCCCC occurs starting at indices 0, 1, and 2. These occurrences overlap, and the result lists that substring just once.

Example 2:

Input: s = "ACGTACGTAC"

Output: []

Explanation: This string has exactly one substring of length 10, so no substring occurs twice. Return an empty array.

Example 3:

Input: s = "ACGTACGTACGTAC"

Output: ["ACGTACGTAC"]

Explanation: The substring ACGTACGTAC occurs at indices 0 and 4. Every other length-10 substring occurs once, so only ACGTACGTAC belongs in the answer.

Constraints:

  • 1 <= s.length <= 100000
  • Every character is A, C, G, or T.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.