Skip to content

Practice Find Polygon With the Largest Perimeter

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2971
LeetCode Problem

Find Polygon With the Largest Perimeter

Problem Statement

You are given an array of positive integers nums of length n. A polygon is a closed plane figure that has at least 3 sides. The longest side of a polygon is smaller than the sum of its other sides. Conversely, if you have k (k >= 3) positive real numbers a1, a2, a3, ..., ak where a1 <= a2 <= a3 <= ... <= ak and a1 + a2 + a3 + ... + ak-1 > ak, then there always exists a polygon with k sides whose lengths are a1, a2, a3, ..., ak. The perimeter of a polygon is the sum of lengths of its sides. Return the largest possible perimeter of a polygon whose sides can be formed from nums, or -1 if it is not possible to create a polygon.

Source: Find Polygon With the Largest Perimeter on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [5,5,5]
Output
15

# Example 2

Input
nums = [1,12,1,2,5,50,3]
Output
12

# Example 3

Input
nums = [5,5,50]
Output
-1

Constraints

3 <= n <= 10^5
1 <= nums[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Find Polygon With the Largest Perimeter.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.