๐บ Triangle Judgement
Given a table containing the lengths of three line segments for each row, your task is to determine whether these three segments can form a valid triangle.
The Challenge: In geometry, three line segments can form a triangle if and only if the sum of any two sides is greater than the third side. This is known as the Triangle Inequality Theorem.
Database Schema:
Table: Triangle
+-------------+------+
| Column Name | Type |
+-------------+------+
| x | int |
| y | int |
| z | int |
+-------------+------+
(x, y, z) is the primary key
Goal: Write a SQL query that returns each row with an additional column indicating whether the three segments can form a triangle. Return "Yes" if they can form a triangle, "No" otherwise.
Triangle Rule: For sides a, b, and c to form a triangle:
โข a + b > c
โข a + c > b
โข b + c > a
All three conditions must be satisfied!
Input & Output
Visualization
Time & Space Complexity
Single pass through all rows in the table
No additional space needed beyond the result set
Constraints
- All side lengths x, y, z are positive integers
- 1 โค x, y, z โค 100
- The table contains at least 1 row
- Key Rule: For a valid triangle, sum of any two sides must be strictly greater than the third side