human
Give me a code to smallest multiple of N formed using the given set of digits and the other steps required given the following:
Smallest multiple of N formed using the given set of digits | Function to return the required number.
Initialize both vectors with their initial values.
Sort the vector of digits.
Initialize the queue.
If modulus value is not present in the queue.
Compute digits modulus given number and update the queue and vectors.
While queue is not empty.
Remove the first element of the queue.
Compute new modulus values by using old queue values and each digit of the set.
If value is not present in the queue.
If required condition can 't be satisfied .
Initialize new vector.
Constructing the solution by backtracking.
Reverse the vector.
Return the required number.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to smallest multiple of N formed using the given set of digits and the other steps required.
 def findSmallestNumber ( arr , n ) :
	dp = [ float ( ' inf ' ) ] * n
	result = [ ( - 1 , 0 ) ] * n
	arr . sort ( )
	q = [ ]
	for i in arr :
		if i != 0 :
			if dp [ i % n ] > 10 ** 9 :
				q . append ( i % n )
				dp [ i % n ] = 1
				result [ i % n ] = - 1 , i
	while len ( q ) > 0 :
		u = q . pop ( 0 )
		for i in arr :
			v = ( u * 10 + i ) % n
			if dp [ u ] + 1 < dp [ v ] :
				dp [ v ] = dp [ u ] + 1
				q . append ( v )
				result [ v ] = u , i
	if dp [ 0 ] > 10 ** 9 :
		return - 1
	else :
		ans = [ ]
		u = 0
		while u != - 1 :
			ans . append ( result [ u ] [ 1 ] )
			u = result [ u ] [ 0 ]
		ans = ans [ : : - 1 ]
		for i in ans :
			return i
if __name__ == " _ _ main _ _ " :
	arr = [ 5 , 2 , 3 ]
	n = 12
	print ( findSmallestNumber ( arr , n ) )