Tap here to switch tabs
Problem
Submissions

Problem: Find Polygon With the Largest Perimeter

Find Polygon With the Largest Perimeter asks you to choose values from an array whose longest side is shorter than all others combined, then return the maximum perimeter or negative one if none works.

Statement

You are given an array of positive integers nums of length n.

A polygon is a closed shape with at least 33 sides. A valid polygon can be formed if and only if the longest side is strictly less than the sum of all its other sides.

The perimeter of a polygon is the sum of the lengths of all its sides.

Return the maximum possible perimeter of a polygon that can be formed using a subset of elements from nums. If it is impossible to form any polygon, return −1-1.

Constraints:

  • 3≤3 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Polygon With the Largest Perimeter

Find Polygon With the Largest Perimeter asks you to choose values from an array whose longest side is shorter than all others combined, then return the maximum perimeter or negative one if none works.

Statement

You are given an array of positive integers nums of length n.

A polygon is a closed shape with at least 33 sides. A valid polygon can be formed if and only if the longest side is strictly less than the sum of all its other sides.

The perimeter of a polygon is the sum of the lengths of all its sides.

Return the maximum possible perimeter of a polygon that can be formed using a subset of elements from nums. If it is impossible to form any polygon, return −1-1.

Constraints:

  • 3≤3 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9