Type of Triangle - Problem

You are given a 0-indexed integer array nums of size 3 which can form the sides of a triangle.

A triangle is called:

  • Equilateral if it has all sides of equal length
  • Isosceles if it has exactly two sides of equal length
  • Scalene if all its sides are of different lengths

Return a string representing the type of triangle that can be formed or "none" if it cannot form a triangle.

Input & Output

Example 1 — Equilateral Triangle
$ Input: nums = [3,3,3]
Output: "equilateral"
💡 Note: All three sides are equal (3 = 3 = 3), and they satisfy triangle inequality (3+3 > 3), so it forms an equilateral triangle.
Example 2 — Isosceles Triangle
$ Input: nums = [3,4,3]
Output: "isosceles"
💡 Note: Two sides are equal (3 = 3), and triangle inequality holds (3+3 > 4), so it forms an isosceles triangle.
Example 3 — Invalid Triangle
$ Input: nums = [1,2,3]
Output: "none"
💡 Note: Triangle inequality fails: 1+2 = 3, which is not greater than 3, so these sides cannot form a triangle.

Constraints

  • nums.length == 3
  • 1 ≤ nums[i] ≤ 109

Visualization

Tap to expand
Triangle Classification ProcessInput: [3, 4, 3]Three side lengthsTriangle Inequality3+4>3, 3+3>4, 4+3>3 ✓Classify TypeTwo sides equal → Isosceles334isosceles
Understanding the Visualization
1
Input
Array of 3 integers representing triangle sides
2
Validate
Check triangle inequality: a+b>c, a+c>b, b+c>a
3
Classify
Determine type based on equal sides
Key Takeaway
🎯 Key Insight: Triangle inequality must be satisfied first, then count equal sides to determine the triangle type
Asked in
Amazon 15 Microsoft 12
12.5K Views
Medium Frequency
~8 min Avg. Time
420 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen