How to solve Maximum Perimeter Triangle in Hackerrank

codingkido
Jul 28, 2017 · 1 min read

After reading the sides of the triangle in an array, Sort them in decreasing order. Because, we need to find out the maximum perimeter.

Run a single for loop, initiating the index to zero , up to (array size - 2).

Check whether, the indexed array element is lesser than the sum of next to elements of the array.

If the condition is satisfied, print those elements in ascending order.

If the condition is not satisfied, print -1.

Here, the code written in Java 8 is attached for your reference.

Thank You, Have a good day.

Please, do comment n the post, so that I can improve.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade