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 program ; Get the side of the 4 small squares ; Find the smallest side ; Get the side of the 4 small squares ; Find the smallest side
< ? php function max1 ( $ a , $ b ) { if ( $ a > $ b ) return $ a ; else return $ b ; } function smallestSide ( $ a ) { sort ( $ a , 0 ) ; $ side1 = $ a [ 0 ] + $ a [ 3 ] ; $ side2 = $ a [ 1 ] + $ a [ 2 ] ; $ side3 = $ a [ 0 ] + $ a [ 1 ] ; $ side4 = $ a [ 2 ] + $ a [ 3 ] ; $ side11 = max1 ( $ side1 , $ side2 ) ; $ side12 = max1 ( $ side3 , $ side4 ) ; $ sideOfSquare = max1 ( $ side11 , $ side12 ) ; return $ sideOfSquare ; } $ side = array ( ) ; echo " Test ▁ Case ▁ 1 STRNEWLINE " ; $ side [ 0 ] = 2 ; $ side [ 1 ] = 2 ; $ side [ 2 ] = 2 ; $ side [ 3 ] = 2 ; echo smallestSide ( $ side ) . " STRNEWLINE " ; echo " Test Case 2 " ; $ side [ 0 ] = 100000000000000 ; $ side [ 1 ] = 123450000000000 ; $ side [ 2 ] = 987650000000000 ; $ side [ 3 ] = 987654321000000 ; echo smallestSide ( $ side ) . " STRNEWLINE " ; ? >