Suppose we have an array nums that contain the size of n sides. We have to check whether we can form a polygon with all of the given sides or not.
So, if the input is like nums = [3, 4, 5], then the output will be True because there are three sides and sum of any two sides is larger than the 3rd one. To solve this, we will use this property where length of one side is smaller than the sum of all other sides.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(nums): nums.sort() if nums[-1] < sum(nums[:-1]): return True return False nums = [3, 4, 5] print (solve(nums))
[3, 4, 5]