3262. Find Polygon With the Largest Perimeter
My accepted Python solution to LeetCode problem 3262, Find Polygon With the Largest Perimeter, running in 68ms.
- Difficulty: Medium
- Python
- Runtime 68ms
- Memory 31.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 68ms, memory 31.6MB, accepted 2025-12-30.
class Solution:
def largestPerimeter(self, nums: List[int]) -> int:
nums.sort()
total = sum(nums)
# Start from largest side and check if it can form a polygon
# A polygon can be formed if the longest side < sum of all other sides
for i in range(len(nums) - 1, 1, -1):
total_except_largest = total - nums[i]
if nums[i] < total_except_largest:
return total
total = total_except_largest
return -1