Question: Problem Description: Given a string replace the largest repeated substring at every point with an asterisk ( * ) . The goal is end result

Problem Description: Given a string replace the largest repeated substring at every point with an asterisk(*). The goal is end result should be a minimal length string after compression
For example, s = "abcabcd" should become "abc*d", Reason: we know abc has repeated twice, so replace the entire second instance of abc with an *.
and if s = "aabbaabb" it should become "a*bb*", Reason: At index 1, a is repeated twice so put an * there, and aabb has repeated twice so replace it's second instance with an *. In this example we don't put an * right after b at index 3 because aab* would represent aabaab, but that isn't the case.
Input:
ABABCABABCE
Output:
6
Explanation:
In the first part, ABAB, AB has repeated twice and it can be replaced as AB* and similarly ABABC is repeated twice and so it can be encoded as AB*C*. The last character is placed as it is and the final encoded format would be AB*C*E and so the length of the minimum encoded string is 6.
input "aabcaabcdeabcabcaabbc"
output-"a * bc * deabc * a * b * c"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!