Form a number divisible by 3 using array digits
Submissions: 2273   Accuracy:


  Difficulty: Easy   Marks: 2

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 “1” and if not print “0”.

The first line consists of an integer T i.e. the number of test cases. First line of each test case consist of an integer n. Next line consists of n spaced integers.

Print '1' if it is possible to form a number divisible by 3 using the array elements otherwise print '0'.

1 <= T <= 100
1 <= n,a[i] <= 105

Input :

40 50 90
1 4

Output : 

Explanation :
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.

** For More Input/Output Examples Use 'Expected Output' option **

Author: saksham0751

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.