Find the Side of the smallest Square that can contain given 4 Big Squares | Function to find the maximum of two values ; Function to find the smallest side of the suitable suitcase ; sort array to find the smallest and largest side of suitcases ; side of the suitcase will be smallest if they arranged in 2 x 2 way so find all possible sides of that arrangement ; since suitcase should be square so find maximum of all four side ; now find greatest side and that will be the smallest square ; return the result ; Driver Code ; Get the side of the 4 small squares ; Find the smallest side ; Get the side of the 4 small squares ; Find the smallest side
def max ( a , b ) : NEW_LINE INDENT if ( a > b ) : NEW_LINE INDENT return a NEW_LINE DEDENT else : NEW_LINE INDENT return b NEW_LINE DEDENT DEDENT def smallestSide ( a ) : NEW_LINE INDENT a . sort ( reverse = False ) NEW_LINE side1 = a [ 0 ] + a [ 3 ] NEW_LINE side2 = a [ 1 ] + a [ 2 ] NEW_LINE side3 = a [ 0 ] + a [ 1 ] NEW_LINE side4 = a [ 2 ] + a [ 3 ] NEW_LINE side11 = max ( side1 , side2 ) NEW_LINE side12 = max ( side3 , side4 ) NEW_LINE sideOfSquare = max ( side11 , side12 ) NEW_LINE return sideOfSquare NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT side = [ 0 for i in range ( 4 ) ] NEW_LINE print ( " Test ▁ Case ▁ 1" ) NEW_LINE side [ 0 ] = 2 NEW_LINE side [ 1 ] = 2 NEW_LINE side [ 2 ] = 2 NEW_LINE side [ 3 ] = 2 NEW_LINE print ( smallestSide ( side ) ) NEW_LINE print ( " " , ▁ end ▁ = ▁ " " ) NEW_LINE print ( " Test ▁ Case ▁ 2" ) NEW_LINE side [ 0 ] = 100000000000000 NEW_LINE side [ 1 ] = 123450000000000 NEW_LINE side [ 2 ] = 987650000000000 NEW_LINE side [ 3 ] = 987654321000000 NEW_LINE print ( smallestSide ( side ) ) NEW_LINE DEDENT