human
Form minimum number from given sequence | Python3 program to print minimum number that can be formed from a given sequence of Is and Ds.
min_avail represents the minimum number which is still available for inserting in the output vector . pos_of_I keeps track of the most recent index where ' I ' was encountered w . r . t the output vector.
Vector to store the output.
Cover the base cases.
Traverse rest of the input.
Print the number.
Driver code"
How can the above be solved in Python?
 Can you provide a code to form minimum number from given sequence and the other steps required?
assistant
#Here is code to form minimum number from given sequence and the other steps required.
 def printLeast ( arr ) :
	min_avail = 1
	pos_of_I = 0
	v = [ ]
	if ( arr [ 0 ] == ' I ' ) :
		v . append ( 1 )
		v . append ( 2 )
		min_avail = 3
		pos_of_I = 1
	else :
		v . append ( 2 )
		v . append ( 1 )
		min_avail = 3
		pos_of_I = 0
	for i in range ( 1 , len ( arr ) ) :
		if ( arr [ i ] == ' I ' ) :
			v . append ( min_avail )
			min_avail += 1
			pos_of_I = i + 1
		else :
			v . append ( v [ i ] )
			for j in range ( pos_of_I , i + 1 ) :
				v [ j ] += 1
			min_avail += 1
	print ( * v , sep = ' ▁ ' )
printLeast ( " IDID " )
printLeast ( " I " )
printLeast ( " DD " )
printLeast ( " II " )
printLeast ( " DIDI " )
printLeast ( " IIDDD " )
printLeast ( " DDIDDIID " )