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 , pr1st integer concatenated with operators ' / ' , ' ( ' and next integers with the operator '/ ; Add parenthesis at the end ; Prthe final expression ; Driver Code
def generateSequence ( arr , n ) : NEW_LINE INDENT ans = " " NEW_LINE ans = str ( arr [ 0 ] ) NEW_LINE if ( n == 1 ) : NEW_LINE INDENT print ( ans ) NEW_LINE DEDENT elif ( n == 2 ) : NEW_LINE INDENT print ( ans + " / " + str ( arr [ 1 ] ) ) NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT else : NEW_LINE INDENT ans += " / ( " + str ( arr [ 1 ] ) NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT ans += " / " + str ( arr [ i ] ) NEW_LINE DEDENT ans += " ) " NEW_LINE print ( ans ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1000 , 100 , 10 , 2 ] NEW_LINE N = len ( arr ) NEW_LINE generateSequence ( arr , N ) NEW_LINE DEDENT