Skip to content
Discussion options

You must be logged in to vote

We need to find the largest perimeter of a triangle with non-zero area using three lengths from the given array. The key insight is that for three lengths to form a triangle, the sum of the two smaller lengths must be greater than the largest length.

Approach

  1. Sorting: First, we sort the array in non-decreasing order. This allows us to efficiently check triplets of lengths starting from the largest possible values.
  2. Checking Triplets: Starting from the end of the sorted array, we check consecutive triplets of lengths. For each triplet (a, b, c) where a ≤ b ≤ c, we check if a + b > c. If this condition holds, these three lengths can form a triangle with the largest possible perimeter starti…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Sep 28, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Sep 28, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants