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 "abcd Reason: we know abc has repeated twice, so replace the entire second instance of abc with an
and if s "aabbaabb" it should become abb Reason: At index 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 because aab would represent aabaab, but that isn't the case.
Input:
ABABCABABCE
Output:
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 ABC The last character is placed as it is and the final encoded format would be ABCE and so the length of the minimum encoded string is
input "aabcaabcdeabcabcaabbc"
outputa bc deabc a b c
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
