File tree Expand file tree Collapse file tree
COVID-19-21-Day-Coding-Streak/Day-6 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ You are given a large number of strings which you have to compress.
3+ If the process of compressing them is correctly done, the original
4+ string can be retreived by decompressing the compressed string. The
5+ process of decompressing is shown below :
6+ 1. Lets say the compressed string is ab*c*x
7+ 2. Iterate over the string from left to right, if you find a '*',
8+ remove it, and simply add a duplicate of the string on the left.
9+ Do this process repeatedly till all stars are removed.
10+
11+ ex: Decompressing : ab*c*d -> ababc*d -> ababcababcd
12+
13+ Your task is to compress string to its smallest possible form. In case
14+ there are multiple ways to compress a string, prefer the one which return
15+ smaller output. For example, if input is zzzzzzz, output should be z*z*z
16+ and not z**zzz
17+
18+ Input: First line of input contains number of test cases T. Then T test
19+ cases follow. Each test case contains the string to be shortened in a
20+ newline. Input string consists solely of small case letters. Input will
21+ be read by driver code.
22+
23+ Output: The shortened string is to be printed as output. Output will be
24+ printed by driver code.
25+
26+ Your task: Your task is to complete the function compress() which takes
27+ the input string as argument and returns the compressed string.
28+
29+ Constraints: T <= 500 ; 1 <= |s| <= 105
30+
31+ Example:
32+ Input:
33+ 2
34+ ababcababcd
35+ zzzzzzz
36+ Output:
37+ ab*c*d
38+ z*z*z
39+
40+ """
You can’t perform that action at this time.
0 commit comments