text: Rearrange array to maximize sum of GCD of array elements with their respective indices | Function to find the maximum sum of GCD ( arr [ i ] , i ) by rearranging the array ; Stores maximum sum of GCD ( arr [ i ] , i ) by rearranging the array elements ; Update res ; Driver Code
code: function findMaxValByRearrArr ( arr , N ) { let res = 0 ; res = parseInt ( ( N * ( N + 1 ) ) / 2 , 10 ) ; return res ; } let arr = [ 3 , 2 , 1 ] ; let N = arr . length ; document . write ( findMaxValByRearrArr ( arr , N ) ) ;