Problem 225158 · easy · Phase 02 Linear Data Structures

Repeated Codons

hash maps · sliding windows · strings

A DNA string dna uses the letters A, C, G, T. A codon is any substring of length 3 (windows overlap). Return a sorted list of the codons that appear more than once in dna.

Examples

Input:  dna = "ATGATGCA"
Output: ["ATG"]
Explanation: windows are ATG, TGA, GAT, ATG, TGC, GCA; only ATG repeats.

Input:  dna = "AC"
Output: []

Constraints

  • 0 <= len(dna) <= 10**5
  • Target complexity: O(n) time plus sorting the (at most 64) results.

Goals

  • Hash overlapping substrings
  • Return a sorted list of keys that meet a count threshold
Starting Python…