human
Largest number with the given set of N digits that is divisible by 2 , 3 and 5 | Function to find the largest integer with the given set.
find sum of all the digits look if any 0 is present or not.
if 0 is not present , the resultant number won 't be divisible by 5.
sort all the elements in a non - decreasing manner.
if there is just one element 0.
find the remainder of the sum of digits when divided by 3.
there can a remainder as 1 or 2.
traverse from the end of the digits.
first element which has the same remainder , remove it.
if there is no element which has a same remainder as y.
subtract it by 3 ( could be one or two ).
delete two minimal digits which has a remainder as y.
print all the digits as a single integer.
Driver code.
initialize the number of set of digits.
initialize all the set of digits in a vector"
Solution in Python:
assistant
#Here is code to largest number with the given set of N digits that is divisible by 2 , 3 and 5 and the other steps required.
 def findLargest ( n , v ) :
	flag = 0
	sum = 0
	for i in range ( n ) :
		if ( v [ i ] == 0 ) :
			flag = 1
		sum += v [ i ]
	if ( flag == 0 ) :
		print ( " Not ▁ possible " )
	else :
		v . sort ( reverse = True )
		if ( v [ 0 ] == 0 ) :
			print ( "0" )
			return 0
		else :
			flag = 0
			y = sum % 3
			if ( y != 0 ) :
				i = n - 1
				while ( i >= 0 ) :
					if ( v [ i ] % 3 == y ) :
						v . remove ( v [ i ] )
						flag = 1
						break
					i -= 1
				if ( flag == 0 ) :
					y = 3 - y
					cnt = 0
					i = n - 1
					while ( i >= 0 ) :
						if ( v [ i ] % 3 == y ) :
							v . remove ( v [ i ] )
							cnt += 1
							if ( cnt >= 2 ) :
								break
						i -= 1
			for i in ( v ) :
			print ( i , end = " " )
if __name__ == ' _ _ main _ _ ' :
	n = 11
	v = [ 3 , 9 , 9 , 6 , 4 , 3 , 6 , 4 , 9 , 6 , 0 ]
	findLargest ( n , v )