All problems
1068EasyArrayMathSortingPolygons

Naming the Shape of Three Rods

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3024Type of Triangle

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

Three rod lengths are given as rods.

Return the name of the triangle they form:

  • "none" when they cannot form a triangle at all, which happens exactly when some two of them added together do not exceed the third;
  • "equilateral" when all three are the same length;
  • "isosceles" when exactly two are the same length;
  • "scalene" when no two are the same length.

Examples

Example 1

Input
rods = [2, 2, 3]
Output
"isosceles"

Two and two added together exceed three, so a triangle is possible, and exactly two of the rods are the same length.

Example 2

Input
rods = [1, 1, 5]
Output
"none"

The two short rods add to two, which does not exceed five, so they cannot close into a triangle at all.

Example 3

Input
rods = [6, 7, 8]
Output
"scalene"

Six and seven exceed eight, so a triangle is possible, and no two rods are the same length.

Constraints

  • rods.length == 3
  • 1 <= rods[i] <= 100

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def triangle_type(rods: list[int]) -> str:
Java
public String triangleType(int[] rods)
September 7
Apply