Type of Triangle

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. - A triangle is called **isosceles** if it has exactly two sides of equal length. - A triangle is called **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.

30:00

Type of Triangle
easy
Free written solution
Topics
Companies

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.
  • A triangle is called isosceles if it has exactly two sides of equal length.
  • A triangle is called 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.

Example 1:
Input: {"nums":[3,3,3]}
Output: equilateral
Constraints:
  • nums.length == 3

  • 1≤nums[i]≤1001 \leq nums[i] \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[3,3,3]}

Three sticks of length 3, 3, 3. First decide whether they close into a triangle at all, then count equal sides.

sides as given

nums[0]

3

nums[1]

3

nums[2]

3

a + b > c

?

a == c

?

a == b or b == c

?

Variables
VariableValue
nums[3,3,3]
DepthFunction Call
Stack empty
0/4