Skip to main content
Back to problems
Leetcode
Easy
Arrays
Math
Type Of Triangle

Classify a triangle from three side lengths.

Acceptance 100%
Problem Statement

Problem

You are given the lengths of three sides. Determine what type of 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.

If the three lengths cannot form a valid triangle, return invalid.

Notes

A valid triangle must satisfy:

  • each side length is positive, and
  • the sum of any two sides is greater than the third side.

Input Format

Three integers representing the side lengths of a triangle.

Output Format

Return one of the strings: equilateral, isosceles, scalene, or invalid.

Constraints

  • Side lengths are integers.
  • Side lengths may be in any order.
  • Use the triangle inequality to determine validity.
Examples
Sample cases returned by the problem API.

Example 1

Input

a = 3, b = 3, c = 3

Output

equilateral

Explanation

All three sides are equal and the triangle inequality holds.

Example 2

Input

a = 4, b = 4, c = 6

Output

isosceles

Explanation

Exactly two sides are equal, and the three lengths can form a valid triangle.

Show 1 more example

Example 3

Input

a = 2, b = 3, c = 7

Output

invalid

Explanation

The sum of the two smaller sides is not greater than the largest side.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.