Triangle Type Classifier

Easy~10 min

Given three positive integers a, b, and c representing side lengths, classify the triangle they form.

Return:

  • "equilateral" if all three sides are equal
  • "isosceles" if exactly two sides are equal
  • "scalene" if all three sides are different
  • "invalid" if the sides cannot form a valid triangle

A triangle is invalid if any side is greater than or equal to the sum of the other two (triangle inequality theorem).

Examples

Example 1
Input: a = 3, b = 3, c = 3
Output: "equilateral"
Explanation: All three sides are equal.
Example 2
Input: a = 3, b = 3, c = 5
Output: "isosceles"
Explanation: Exactly two sides (a and b) are equal.
Example 3
Input: a = 3, b = 4, c = 5
Output: "scalene"
Explanation: All three sides are different.
Example 4
Input: a = 1, b = 2, c = 3
Output: "invalid"
Explanation: 1 + 2 = 3, which is not strictly greater than 3. These sides cannot form a triangle.

Constraints

  • 1 <= a, b, c <= 10^6
  • a, b, and c are positive integers.
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run