Arrange the numbers in the Array as per given inequalities | Function to place the integers in between the inequality signs ; Sort the integers array and set the index of smallest and largest element ; Iterate over the inequalities ; Append the necessary integers per symbol ; Add the final integer ; Return the answer ; Driver Code ; Given List of Integers ; Given list of inequalities ; Function Call ; Print the output
def formAnInequality ( integers , inequalities ) : NEW_LINE INDENT integers . sort ( ) NEW_LINE lowerIndex = 0 NEW_LINE higherIndex = len ( integers ) - 1 NEW_LINE sb = " " NEW_LINE for ch in inequalities : NEW_LINE INDENT if ( ch == ' < ' ) : NEW_LINE INDENT sb += ( " ▁ " + chr ( integers [ lowerIndex ] ) + " ▁ " + ch ) NEW_LINE lowerIndex += 1 NEW_LINE DEDENT else : NEW_LINE INDENT sb += ( " ▁ " + chr ( integers [ higherIndex ] ) + " ▁ " + ch ) NEW_LINE higherIndex -= 1 NEW_LINE DEDENT DEDENT sb += ( " ▁ " + chr ( integers [ lowerIndex ] ) ) NEW_LINE return sb NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT integers = [ 2 , 5 , 1 , 0 ] NEW_LINE inequalities = [ ' < ' , ' > ' , ' < ' ] NEW_LINE output = formAnInequality ( integers , inequalities ) NEW_LINE print ( output ) NEW_LINE DEDENT