Magicsheet logo

Classifying Triangles by Lengths

Easy
88.5%
Updated 6/1/2025

Asked by 1 Company

Topics

Classifying Triangles by Lengths

What is this problem about?

This is a SQL / Logic problem where you are given a table Triangles with three columns representing the lengths of the three sides: A, B, and C. You need to classify each row as:

  • Equilateral: All three sides are equal.
  • Isosceles: Two sides are equal.
  • Scalene: All three sides are different.
  • Not A Triangle: The sides do not satisfy the triangle inequality theorem (A+B>CA+B > C, A+C>BA+C > B, and B+C>AB+C > A).

Why is this asked in interviews?

This is a common question at Aon and other data-focused companies. It tests your ability to implement conditional logic in SQL using the CASE statement. It also evaluates your basic geometry knowledge and whether you can handle the "Not A Triangle" edge case before performing the classification.

Algorithmic pattern used

The pattern is Conditional Logic (CASE WHEN). You must evaluate the conditions in a specific order:

  1. Check if the three sides form a valid triangle.
  2. If valid, check if all sides are equal.
  3. If not all equal, check if any two sides are equal.
  4. If none are equal, it must be scalene.

Example explanation

ABC
202020
202030
203040
101030

Common mistakes candidates make

The most significant mistake is forgetting the triangle inequality check. Without it, sides like (10, 10, 30) might be incorrectly classified as "Isosceles." Another mistake is not putting the CASE conditions in the right order—the equilateral check must come before the isosceles check.

Interview preparation tip

When using CASE statements, always put the most restrictive or important conditions first. SQL evaluates the WHEN clauses in order and stops at the first match.

Similar Questions