Repeated DNA Sequences

MediumArrays & Hashinghashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A DNA strand is a string over the letters 'A', 'C', 'G' and 'T'. Given a strand s, find every sequence of exactly **10 letters** that appears as a substring of s at least twice. Occurrences may overlap. Return the qualifying sequences **sorted in ascending lexicographic order**, each listed once. Return an empty list if there are none.

Examples

Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
Output: ["AAAAACCCCC","CCCCCAAAAA"]
Both 10-letter sequences occur twice; they are listed in sorted order.
Input: s = "AAAAAAAAAAAAA"
Output: ["AAAAAAAAAA"]
The run of ten As starts at indices 0, 1, 2 and 3 (overlapping occurrences count).

Constraints

  • 0 <= s.length <= 10^5
  • `s[i]` is one of 'A', 'C', 'G', 'T'.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems