VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-whether-triangle-valid-not-sides-given/

⇱ Check whether triangle is valid or not if sides are given - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check whether triangle is valid or not if sides are given

Last Updated : 10 Feb, 2025

Given three sides, check whether triangle is valid or not. 

Examples:  

Input : a = 7, b = 10, c = 5
Output : Valid
We can draw a triangle with the given three edge lengths.

Input : a = 1, b = 10, c = 12
Output : Invalid
We can not draw a triangle with the given three edge lengths.

Approach: A triangle is valid if sum of its two sides is greater than the third side. If three sides are a, b and c, then three conditions should be met. 

  • (a + b) > c
  • (a + c) > b
  • (b + c) > a  

👁 Check whether triangle is valid or not if sides are given



Output
Valid

Time Complexity: O(1)
Auxiliary Space: O(1)

Comment