Generate a sequence such that float division of array elements is maximized | Function to place the parenthesis such that the result is maximized ; Store the required string ; Add the first integer to string ; If the size of array is 1 ; If the size of array is 2 , print the 1 st integer followed by / operator followed by the next integer ; If size of array is exceeds two , print 1 st integer concatenated with operators ' / ' , ' ( ' and next integers with the operator ' / ' ; Add parenthesis at the end ; Print the final expression ; Driver Code
function generateSequence ( arr , n ) { var ans ; ans = ( arr [ 0 ] . toString ( ) ) ; if ( n == 1 ) document . write ( ans ) ; else if ( n == 2 ) { document . write ( ans + " " + ( arr [ 1 ] . toString ( ) ) ) ; } else { ans += " " + ( arr [ 1 ] . toString ( ) ) ; for ( var i = 2 ; i < n ; i ++ ) { ans += " " + ( arr [ i ] . toString ( ) ) ; } ans += " " ; document . write ( ans ) ; } } var arr = [ 1000 , 100 , 10 , 2 ] ; var N = arr . length ; generateSequence ( arr , N ) ;