Maximized partitions of a string such that each character of the string appears in one substring | Function to print all the substrings ; Stores the substrings ; Stores last index of characters of string s ; Find the last position of each character in the string ; Update the last index ; Iterate the given string ; Get the last index of s [ i ] ; Extend the current partition characters last pos ; If the current pos of character equals the min pos then the end of partition ; Add the respective character to the string ; Store the partition 's  len and reset variables ; Update the minp and str ; Input string ; Function call
def print_substring ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE str = " " NEW_LINE ans = [ ] NEW_LINE if ( n == 0 ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE return NEW_LINE DEDENT last_pos = [ - 1 ] * 26 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ] == - 1 ) : NEW_LINE INDENT last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ] = i NEW_LINE DEDENT DEDENT minp = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT lp = last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ] NEW_LINE minp = max ( minp , lp ) NEW_LINE if ( i == minp ) : NEW_LINE INDENT str += s [ i ] NEW_LINE print ( str , end = " ▁ " ) NEW_LINE minp = - 1 NEW_LINE str = " " NEW_LINE DEDENT else : NEW_LINE INDENT str += s [ i ] NEW_LINE DEDENT DEDENT DEDENT S = " ababcbacadefegdehijhklij " NEW_LINE print_substring ( S ) NEW_LINE