human
Write me a code to minimum number greater than the maximum of array which cannot be formed using the numbers in the array and the other steps required given the following:
Minimum number greater than the maximum of array which cannot be formed using the numbers in the array | Function that returns the minimum number greater than Maximum of the array that cannot be formed using the elements of the array.
Sort the given array.
Maximum number in the array.
table [ i ] will store the minimum number of elements from the array to form i.
Calculate the minimum number of elements from the array required to form the numbers from 1 to ( 2 * Max ).
If there exists a number greater than the Maximum element of the array that can be formed using the numbers of array.
Driver code"
Solution in Python:
assistant
#Here is code to minimum number greater than the maximum of array which cannot be formed using the numbers in the array and the other steps required.
 def findNumber ( arr , n ) :
	arr = sorted ( arr )
	Max = arr [ n - 1 ]
	table = [ 10 ** 9 for i in range ( ( 2 * Max ) + 1 ) ]
	table [ 0 ] = 0
	ans = - 1
	for i in range ( 1 , 2 * Max + 1 ) :
		for j in range ( n ) :
			if ( arr [ j ] <= i ) :
				res = table [ i - arr [ j ] ]
				if ( res != 10 ** 9 and res + 1 < table [ i ] ) :
					table [ i ] = res + 1
		if ( i > arr [ n - 1 ] and table [ i ] == 10 ** 9 ) :
			ans = i
			break
	return ans
arr = [ 6 , 7 , 15 ]
n = len ( arr )
print ( findNumber ( arr , n ) )