Minimum sum of two numbers formed from digits of an array | Function to find and return minimum sum of two numbers formed from digits of the array . ; sort the array ; let two numbers be a and b ; fill a and b with every alternate digit of input array ; return the sum ; Driver Code
function solve ( arr , n ) { arr . sort ( ) ; let a = 0 , b = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ; else b = b * 10 + arr [ i ] ; } return a + b ; } let arr = [ 6 , 8 , 4 , 5 , 2 , 3 ] ; let n = arr . length ; document . write ( " " + solve ( arr , n ) ) ;