Maximum amount of money that can be collected by a player in a game of coins | Function to calculate the maximum amount collected by A ; Stores the money obtained by A ; Stores mid elements of odd sized rows ; Size of current row ; Increase money collected by A ; Add coins at even indices to the amount collected by A ; Print the amount ; Driver Code ; Function call to calculate the amount of coins collected by A
def find ( N , Arr ) : NEW_LINE INDENT amount = 0 NEW_LINE mid_odd = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT siz = len ( Arr [ i ] ) NEW_LINE for j in range ( 0 , siz // 2 ) : NEW_LINE INDENT amount = amount + Arr [ i ] [ j ] NEW_LINE DEDENT if ( siz % 2 == 1 ) : NEW_LINE INDENT mid_odd . append ( Arr [ i ] [ siz // 2 ] ) NEW_LINE DEDENT DEDENT mid_odd . sort ( reverse = True ) NEW_LINE for i in range ( len ( mid_odd ) ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT amount = amount + mid_odd [ i ] NEW_LINE DEDENT DEDENT print ( amount ) NEW_LINE DEDENT N = 2 NEW_LINE Arr = [ [ 5 , 2 , 3 , 4 ] , [ 1 , 6 ] ] NEW_LINE find ( N , Arr ) NEW_LINE