

You don’t have to print anything, it has already been taken care of. Just implement the function.
The string will contain lowercase alphabets only.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first and only line of each test case contains string S..
For each test case, the list containing the size of partitions will be printed.
The output of each test case is printed in a separate line.
1 <= T <= 10
1 <= N <= 5 * 10^4
Where ‘T’ is the total number of test cases and N represents the length of the string S.
The idea is to find the ending index of the current partition.Traverse the string and for the current character, find its last occurring index and check whether this value is greater than the value of last occurring index of any previous character. Update the ending index of the current partition, if required. The end of any partition will be marked if all the characters of that partition have their last occurring index less than or equal to the current index. Repeat this procedure until the end of the string and find the lengths of all the partitions made.
Algorithm:
The problem says to partition the string, so finding the first and last occurrence of each character of the string, we get some intervals. Merge the overlapping intervals and store their lengths in a list and return it.
The idea is to find the ending index of the current partition. Precompute the last occurring index for all characters by traversing the string and storing every character’s last occurring index in a list. Again traverse the string and for the current character get its last occurring index from the precomputed list and check whether this value is greater than the value of last occurring index of any previous character. Update the ending index of the current partition, if required. The end of any partition will be marked if all the characters of that partition have their last occurring index less than or equal to the current index. Repeat this procedure until the end of the string and find the lengths of all the partitions made.