Introduction
This is a little challenge with the goal of identifying repeated pattern "blocks" in a string, and outputting them with their frequency of occurence from left to right.
A friend asked me this question and I realized it wasn't as simple as tossing what you've seen into a hash table and popping them off if previously seen.
Example Input and Output
Input:
"TTBBPPPBPBPBPBBBBPBPBPBB"
The idea:
T T | B B | P P P | BP BP BP | B B B B | PB PB PB | B
Output:
2T, 2B, 3P, 3BP, 4B, 3PB, B
However any output format that shows the number of repetitions, and respective repeated substrings, are allowed.
Is it possible to do this with reasonable time complexity?
I'm curious as to the standard, legible approach to this kind of question, but as this is code golf - shortest code wins!
Cheers!
"ABABCABCBC"? \$\endgroup\$AAABBBAAABBBis it[A3, B3, A3, B3],[AAABBB2], or[[A3, B3]2]? \$\endgroup\$