Tuesday, October 7, 2025
HomeData Modelling & AIPython Program to check whether it is possible to make a divisible...

Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array

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)>


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!

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Dominic
32340 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6708 POSTS0 COMMENTS
Nicole Veronica
11872 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6829 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6780 POSTS0 COMMENTS
Umr Jansen
6784 POSTS0 COMMENTS