An array of size n is given. The array contains digits from 0 to 9. Generate the largest number using the digits in the array such that the number is divisible by 2, 3 and 5.

For example, if the arrays is {1, 8, 7, 6, 0}, output must be: 8760. And if the arrays is {7, 7, 7, 6}, output must be: “no number can be formed”.

Source: Amazon Interview | Set 7

This problem is a variation of “Find the largest multiple of 3“.

Since the number has to be divisible by 2 and 5, it has to have last digit as 0. So if the given array doesn’t contain any zero, then no solution exists.

Once a 0 is available, extract 0 from the given array. Only thing left is, the number should be is divisible by 3 and the largest of all. Which has been discussed here.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find the largest multiple of 3 from array of digits | Set 2 (In O(n) time and O(1) space)
- Find the largest multiple of 3 | Set 1 (Using Queue)
- Find the largest possible k-multiple set
- Find the largest N digit multiple of N
- Find multiple of x closest to or a ^ b (a raised to power b)
- Find the multiple of x which is closest to a^b
- Find First element in AP which is multiple of given prime
- Find if there exists multiple ways to draw line through (x, y) to cut rectangle in equal halfs
- Find Nth number in a sequence which is not a multiple of a given number
- Check if a number is multiple of 5 without using / and % operators
- Smallest integer with digit sum M and multiple of N
- Number of triplets such that each value is less than N and each pair sum is a multiple of K
- Count ways to reach the Nth stair using multiple 1 or 2 steps and a single step 3
- Find the Largest number with given number of digits and sum of digits
- Find the original matrix when largest element in a row and a column are given
- Legendre's formula (Given p and n, find the largest x such that p^x divides n!)
- Write an Efficient Method to Check if a Number is Multiple of 3
- Check if a number is multiple of 9 using bitwise operators
- n'th multiple of a number in Fibonacci Series
- N-th multiple in sorted list of multiples of two numbers