


If there are multiple solutions of a string, return the string with minimum total length.
Let str = abaccce
Now In this example, we can make a maximum of three substrings i.e. {‘b’, ‘ccc’, ‘e’}.
There can be one more solution with maximum substrings equal to three i.e. {‘aba’, ‘ccc’, ‘e’} but we have to select the substrings with minimum total length. So the final answer is {‘b’, ‘ccc’, ‘e’}.
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first and only line of each test case contains a string “str”.
For each test case, print a list of strings “ans”.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
1 <= T <= 10
1 <= |str| <= 10^5, where |str| represents the length of the String str.
Time limit: 1 sec
The approach is simple, take two arrays left and right which will store the first and last occurrences of every character of the string and we will check for each position of the string if it is the minimum possible substring satisfying the given conditions.
The steps are as follows: