Hello **Programmers/Coders,** Today we are going to share ** solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java**. At Each Problem with Successful submission with

**all Test Cases Passed,**you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for **Maximum Perimeter Triangle** **in Java-HackerRank Problem**. We are providing the **correct and tested solutions** of coding problems present on **HackerRank**. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

**Introduction To Algorithm**

The word **Algorithm** means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.

**Advantages of Algorithms:**

- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.

** Link for the Problem** – Maximum Perimeter Triangle – Hacker Rank Solution

Maximum Perimeter Triangle – Hacker Rank Solution

**Problem:**

Given an array of stick lengths, use of them to construct a non-degenerate triangle with the maximum possible perimeter. Return an array of the lengths of its sides as integers in non-decreasing order.

If there are several valid triangles having the maximum perimeter:

- Choose the one with the
*longest maximum side*. - If more than one has that maximum, choose from them the one with the
*longest minimum side*. - If more than one has that maximum as well, print any one them.

If no non-degenerate triangle exists, return .

**Example**

The triplet will not form a triangle. Neither will or , so the problem is reduced to and . The longer perimeter is .

**Function Description**

Complete the *maximumPerimeterTriangle* function in the editor below.

maximumPerimeterTriangle has the following parameter(s):

*int sticks[n]:*the lengths of sticks available

**Returns**

*int[3] or int[1]:*the side lengths of the chosen triangle in non-decreasing order or -1

**Input Format**

The first line contains single integer , the size of array .

The second line contains space-separated integers , each a stick length.

**Constraints**

**Sample Input 0**

5 1 1 1 3 3

**Sample Output 0**

1 3 3

**Explanation 0**

There are possible unique triangles:

The second triangle has the largest perimeter, so we print its side lengths on a new line in non-decreasing order.

**Sample Input 1**

3 1 2 3

**Sample Output 1**

-1

**Explanation 1**

The triangle is degenerate and thus can’t be constructed, so we print `-1`

on a new line.

**Sample Input 2**

6 1 1 1 2 3 5

**Sample Output 2**

1 1 1

**Explanation 2**

The triangle (1,1,1) is the only valid triangle.

Maximum Perimeter Triangle – Hacker Rank Solution

import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] sticks = new int[n]; for(int i=0; i < n; i++){ sticks[i] = in.nextInt(); } Arrays.sort(sticks); int trianglePosition = n-3; while ((trianglePosition>=0) && (sticks[trianglePosition] + sticks[trianglePosition+1] <= sticks[trianglePosition+2])) { trianglePosition--; } if (trianglePosition < 0) { System.out.println(-1); } else { System.out.println(sticks[trianglePosition] + " " + sticks[trianglePosition + 1] + " " + sticks[trianglePosition + 2]); } /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ } }

brand tadalafil 10mg buy tadalafil 20mg without prescription causes of erectile dysfunction

cheap cefadroxil 250mg finasteride 1mg cheap oral propecia

generic diflucan 100mg ampicillin 250mg cheap buy ciprofloxacin 500mg for sale

order generic flagyl 200mg purchase septra without prescription buy generic keflex online

buy cleocin 150mg for sale order cleocin 300mg online sildenafil uk

order tamoxifen 20mg pills rhinocort online order buy ceftin 250mg pill

buy sildenafil 100mg without prescription buy generic sildalis sildenafil for men over 50

isotretinoin over the counter buy amoxicillin 500mg generic azithromycin price

azithromycin online order buy omnacortil neurontin 100mg usa

buy lasix for sale diuretic order furosemide 100mg sale buy ventolin inhalator sale

where to buy ramipril without a prescription oral ramipril 10mg buy etoricoxib sale

buy levitra cheap brand tizanidine plaquenil over the counter

asacol 400mg canada order azelastine 10 ml online avapro 150mg tablet

temovate cost buy generic amiodarone cordarone 200mg cost

buy generic benicar online order verapamil 120mg online cheap depakote 250mg brand

purchase temovate online cheap order cordarone 200mg sale buy cordarone generic

order coreg 6.25mg online carvedilol 6.25mg cheap buy chloroquine medication

acetazolamide 250mg brand purchase isosorbide pills azathioprine 50mg tablet

buy digoxin without prescription molnupiravir for sale online oral molnunat 200 mg

naprosyn 500mg pills naproxen us prevacid 15mg usa

order generic proventil 100 mcg albuterol medication buy pyridium 200mg generic

montelukast 5mg for sale order montelukast 10mg generic buy avlosulfon 100 mg

buy olumiant tablets lipitor 10mg pill atorvastatin 80mg price

adalat 30mg brand brand perindopril purchase allegra for sale