The "Triangle Judgement coding problem" is a foundational SQL task. You are given a table Triangle containing three columns: x, y, and z, representing the lengths of three line segments. Your goal is to determine, for each row, whether these three segments can form a valid triangle. According to the triangle inequality theorem, a triangle can only be formed if the sum of the lengths of any two sides is strictly greater than the length of the third side.
This "Triangle Judgement interview question" is often used in preliminary rounds for data-focused roles at companies like Uber and Meta. It validates that the candidate understands basic geometric principles and can implement them using SQL conditional logic. It's a test of "clean code" in SQL—can you write a query that is both correct and easy to read using IF or CASE statements?
The "Database interview pattern" for this problem relies on the CASE or IF expression. For each row, we evaluate the condition: x + y > z AND x + z > y AND y + z > x. If this condition is true, the result is "Yes"; otherwise, it is "No". This is a simple per-row operation with time complexity.
Table Data:
triangle, containing these "Yes"/"No" values.A common mistake in the "Triangle Judgement coding problem" is only checking one combination of sides (e.g., x + y > z). You must check all three combinations to ensure the segments can form a triangle regardless of which side is the longest. Another error is using >= instead of >, which is incorrect as the sum must be strictly greater.
For the "Database interview pattern," practice using CASE WHEN for multi-condition branching. It is more standard and portable across different SQL dialects (like MySQL, PostgreSQL, and SQL Server) compared to the IF function.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Fix Names in a Table | Easy | Solve | |
| Not Boring Movies | Easy | Solve | |
| Primary Department for Each Employee | Easy | Solve | |
| Queries Quality and Percentage | Easy | Solve | |
| Employee Bonus | Easy | Solve |