human
Count maximum concatenation of pairs from given array that are divisible by 3 | Function to count pairs whose concatenation is divisible by 3 and each element can be present in at most one pair.
Stores count pairs whose concatenation is divisible by 3 and each element can be present in at most one pair.
Check if an element present in any pair or not.
Generate all possible pairs.
If the element already present in a pair.
If the element already present in a pair.
If concatenation of elements is divisible by 3.
Update ans.
Mark i is True.
Mark j is True.
Driver Code.
To display the result"
Solution in Python:
assistant
#Here is code to count maximum concatenation of pairs from given array that are divisible by 3 and the other steps required.
 def countDivBy3InArray ( arr ) :
	ans = 0
	taken = [ False ] * len ( arr )
	for i in range ( len ( arr ) ) :
		if taken [ i ] :
			continue
		for j in range ( i + 1 , len ( arr ) ) :
			if taken [ j ] :
				continue
			if ( not int ( str ( arr [ i ] ) + str ( arr [ j ] ) ) % 3 or not int ( str ( arr [ j ] ) + str ( arr [ i ] ) ) % 3 ) :
				ans += 1
				taken [ i ] = True
				taken [ j ] = True
	return ans
arr = [ 5 , 3 , 2 , 8 , 7 ]
print ( countDivBy3InArray ( arr ) )