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
function find ( N , Arr ) { var amount = 0 ; var mid_odd = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { var siz = Arr [ i ] . length ; for ( var j = 0 ; j < siz / 2 ; j ++ ) amount = amount + Arr [ i ] [ j ] ; if ( siz % 2 == 1 ) mid_odd . push ( Arr [ i ] [ siz / 2 ] ) ; } mid_odd . sort ( ( a , b ) => a - b ) for ( var i = 0 ; i < mid_odd . length ; i ++ ) if ( i % 2 == 0 ) amount = amount + mid_odd [ i ] ; document . write ( amount + " " ) ; } var N = 2 ; var Arr = [ [ 5 , 2 , 3 , 4 ] , [ 1 , 6 ] ] ; find ( N , Arr ) ;