Improve Article Save Article Like Article Given two sides of a triangle s1 and s2, the task is to find the minimum and maximum possible length of the third side of the given triangle. Print -1 if it is not possible to make a triangle with the given side lengths. Note that the length of all the sides must be integers.
Approach: Let s1, s2 and s3 be the sides of the given triangle where s1 and s2 are given. As we know that in a triangle, the sum of two sides must always be greater than the third side. So, the following equations must be satisfied:
Solving for s3, we get s3 < s1 + s2, s3 > s2 – s1 and s3 > s1 – s2.
Time Complexity: O(1) Auxiliary Space: O(1) |