The Find Polygon With the Largest Perimeter interview question is a geometry-based array problem. A polygon with sides () can only be formed if the length of its longest side is strictly less than the sum of the lengths of the other sides. You are given an array of side lengths, and you need to find the maximum possible perimeter of any polygon that can be constructed using a subset of these lengths.
Companies like Microsoft and Airtel ask this to evaluate your understanding of Greedy interview patterns and sorting. It tests if you can identify that to maximize the perimeter, you should try to include as many large sides as possible, provided they satisfy the polygon inequality theorem. It’s a test of combining Math interview patterns with efficient array processing.
This problem follows the Greedy and Prefix Sum patterns.
nums[i], check if nums[i] < prefixSum[i].
prefixSum[i] + nums[i]. Since you started from the largest possible i, this is your maximum perimeter.nums[i] as the longest side. Move to .Array: [1, 12, 1, 2, 5, 50]
[1, 1, 2, 5, 12, 50][0, 1, 2, 4, 9, 21] (where prefixSum[i] is sum of elements 0 to i-1).[1, 1, 2]. is False.
Example 2: [5, 5, 5][5, 5, 5]. Prefix Sum for last 5: . is True. Perimeter = 15.Whenever a problem involves a "sum of others" constraint (like the triangle inequality), Sorting is almost always the prerequisite. It allows you to check the most constrained case (the largest element) against the largest possible pool of support (all smaller elements).
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximum Sum Obtained of Any Permutation | Medium | Solve | |
| Rearrange Array to Maximize Prefix Score | Medium | Solve | |
| Zero Array Transformation III | Medium | Solve | |
| Removing Minimum Number of Magic Beans | Medium | Solve | |
| Maximum Price to Fill a Bag | Medium | Solve |