Check if it is possible to create a polygon with given n sides | Function that returns true if it is possible to form a polygon with the given sides ; Sum stores the sum of all the sides and maxS stores the length of the largest side ; If the length of the largest side is less than the sum of the other remaining sides ; Driver code
< ? php function isPossible ( $ a , $ n ) { $ sum = 0 ; $ maxS = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sum += $ a [ $ i ] ; $ maxS = max ( $ a [ $ i ] , $ maxS ) ; } if ( ( $ sum - $ maxS ) > $ maxS ) return true ; return false ; } $ a = array ( 2 , 3 , 4 ) ; $ n = count ( $ a ) ; if ( isPossible ( $ a , $ n ) ) echo " Yes " ; else echo " No " ; ? >