FunctionRacerProblemsRace

Largest Perimeter Triangle

EasySorting and searchingPython, JavaScript, TypeScript, Java, C++

Each item of nums is a stick length. Pick three sticks that can form a triangle with positive area (the two shorter sticks must add up to more than the longest). Return the biggest perimeter such a triangle can have.

Return 0 if no triangle is possible.

Example 1

nums [2,1,2]
returns 5

Sides 2, 1, 2: perimeter 5.

Example 2

nums [1,2,1,10]
returns 0

No three sticks work.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems