Problem 338
Repeated DNA Sequences
Medium · 20 pts · String, Hash Table, Sliding Window, Rolling Hash
Problem
A DNA strand is written with the letters A, C, G and T. Find every sequence of exactly 10 letters that occurs more than once as a substring of the strand (occurrences may overlap). Print each such sequence once, in lexicographic (dictionary) order, one per line. Print NONE if no 10-letter sequence repeats.
Input
A single string S of the letters A, C, G and T.
Output
Print the repeated sequences in lexicographic order, one per line, or NONE.
Constraints
1 <= |S| <= 100000
Example input
AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT
Example output
AAAAACCCCC CCCCCAAAAA
Explanation
In AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT the sequences AAAAACCCCC and CCCCCAAAAA each appear twice, and they are printed in alphabetical order.