• Customer Support: admin@thealgorists.com
  • Feedback: We are listening to your every feedback, and taking action to constantly improve your learning experience. If you have any feedback, please use this form: https://thealgorists.com/Feedback.
  • If you are a student, email to admin@thealgorists.com to get special student discount.



Problem Statement:


All DNA is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T', for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.
Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.

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

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

Solution:



Please get yourself familiar with Fundamentals of Sliding Window Technique and go through the solutions for all the previous Sliding Window problems ( Grumpy Bartender, Longest Substring With Atmost Two Distinct Characters, Longest Substring With Atmost K Distinct Characters, Longest Substring Without Repeating Characters, Find All Anagrams ) really well, and try to solve the problem yourself before looking at the solution below.

We keep a window of length 10 which we would be slide across the given string (DNA). The window would represent 10-letter-long DNA sequences. As we go on encountering new 10-letter-long DNA sequence we store that in a data structure. If at any time we find a window matches any of the stored unique DNA sequences we would know that we have found a repeated DNA sequence.



Java Solution:



This is a Premium content. Please subscribe to access the code.
After subscribing please come back and refresh this page.




Python Solution:



This is a Premium content. Please subscribe to access the code.
After subscribing please come back and refresh this page.






The above content is written by:

Abhishek Dey

Abhishek Dey

A Visionary Software Engineer With A Mission To Empower Every Person & Every Organization On The Planet To Achieve More

Microsoft | University of Florida

View LinkedIn profile


If you have any feedback, please use this form: https://thealgorists.com/Feedback.




Subscribe to Our Youtube Channel

Follow Us On LinkedIn
wave