Given an array of integers, the task is to find whether it’s possible to construct an integer using all the digits of these numbers such that it would be divisible by 3. If it is possible then print “Yes” and if not print “No”.

Examples:

Input : arr[] = {40, 50, 90} Output : Yes We can construct a number which is divisible by 3, for example 945000. So the answer is Yes. Input : arr[] = {1, 4} Output : No The only possible numbers are 14 and 41, but both of them are not divisible by 3, so the answer is No.

`# Python program to find if it is possible ` `# to make a number divisible by 3 using ` `# all digits of given array ` ` ` `def` `isPossibleToMakeDivisible(arr, n): ` ` ` `# Find remainder of sum when divided by 3 ` ` ` `remainder ` `=` `0` ` ` `for` `i ` `in` `range` `(` `0` `, n): ` ` ` `remainder ` `=` `(remainder ` `+` `arr[i]) ` `%` `3` ` ` ` ` `# Return true if remainder is 0. ` ` ` `return` `(remainder ` `=` `=` `0` `) ` ` ` `# main() ` ` ` `arr ` `=` `[` `40` `, ` `50` `, ` `90` `]; ` `n ` `=` `3` `if` `(isPossibleToMakeDivisible(arr, n)): ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# Code Contributed by Mohit Gupta_OMG <(0_o)> ` |

*chevron_right*

*filter_none*

**Output:**

Yes

Time Complexity : O(n)

Please refer complete article on Possible to make a divisible by 3 number using all digits in an array for more details!

## Recommended Posts:

- Python Program to print all Possible Combinations from the three Digits
- Python Program for Check if all digits of a number divide it
- Python program to check whether a number is Prime or not
- Python Program to Check Whether a Number is Positive or Negative or zero
- Python | Check possible bijection between sequence of characters and digits
- Python program to check whether the string is Symmetrical or Palindrome
- Python program to check whether the values of a dictionary are in same order as in a list
- Program to print all the numbers divisible by 3 and 5 for a given number
- Python - Check whether a string starts and ends with the same character or not (using Regular Expression)
- Python - Check whether the given List forms Contiguous Distinct Sub-Array or Not
- Python regex | Check whether the input is Floating point number or not
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python program to find the sum of all even and odd digits of an integer list
- Python Program for Largest K digit number divisible by X
- Python Program for Smallest K digit number divisible by X
- Python program to find all possible pairs with given sum
- Check whether a number has consecutive 0's in the given base or not
- Python | Check whether a string is valid json or not
- Python | Check whether string contains only numbers or not
- Python | Check whether two lists follow same pattern or not