text: Minimize cost to Swap two given Arrays | Function to calculate and return the minimum cost required to swap two arrays ; Return the total minimum cost ; Driver Code
code: function getMinCost ( A , B , N ) { let mini = Number . MAX_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { mini = Math . min ( mini , Math . min ( A [ i ] , B [ i ] ) ) ; } return mini * ( 2 * N - 1 ) ; } let N = 3 ; let A = [ 1 , 4 , 2 ] ; let B = [ 10 , 6 , 12 ] ; document . write ( getMinCost ( A , B , N ) ) ;