Modify a given array by replacing each element with the sum or product of their digits based on a given condition | Function to modify the given array as per the given conditions ; Traverse the given array arr [ ] ; Initialize the count of even and odd digits ; Initialize temp with the current array element ; For count the number of even digits ; Increment the odd count ; Otherwise ; Divide temp by 10 ; Performe addition ; Performe multiplication ; Otherwise ; Driver Code
def evenOdd ( arr , N ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT even_digits = 0 ; NEW_LINE odd_digits = 0 ; NEW_LINE temp = arr [ i ] ; NEW_LINE while ( temp ) : NEW_LINE INDENT if ( ( temp % 10 ) & 1 ) : NEW_LINE INDENT odd_digits += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT even_digits += 1 ; NEW_LINE DEDENT temp = temp // 10 NEW_LINE DEDENT if ( even_digits > odd_digits ) : NEW_LINE INDENT res = 0 ; NEW_LINE while ( arr [ i ] ) : NEW_LINE INDENT res += arr [ i ] % 10 ; NEW_LINE arr [ i ] = arr [ i ] // 10 ; NEW_LINE DEDENT print ( res , end = " ▁ " ) ; NEW_LINE DEDENT elif ( odd_digits > even_digits ) : NEW_LINE INDENT res = 1 ; NEW_LINE while ( arr [ i ] ) : NEW_LINE INDENT res *= arr [ i ] % 10 ; NEW_LINE arr [ i ] = arr [ i ] // 10 NEW_LINE DEDENT print ( res , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT arr = [ 113 , 141 , 214 , 3186 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE evenOdd ( arr , N ) ; NEW_LINE