# Maximum Perimeter Triangle Hacker Rank Solution Best & Easiest

Maximum Perimeter Triangle Problem Solution

In this post, we will solve the Maximum Perimeter Triangle HackerRank Solution. This problem (Maximum Perimeter Triangle) is a part of the HackerRank Problem Solving series.

## Maximum Perimeter Triangle Hacker Rank Solution

### Problem solution in Python programming:

```def maximumPerimeterTriangle(sticks):
arr = sorted(sticks)
res = [-1]
for i in range(len(arr)-2):
cut = arr[i:i+3]
if cut[0] + cut[1] > cut[2]:
res = cut
return res
```

### Problem solution in C++ programming:

```vector<int> maximumPerimeterTriangle(vector<int> sticks) {
vector<int> maxtriangle;
sort(sticks.begin(),sticks.end(),greater<int>());
{
for(int i=0;i<=sticks.size()-3;i++)
{
if(sticks[i+1]+sticks[i+2]>sticks[i])
{
maxtriangle.push_back(sticks[i+2]);
maxtriangle.push_back(sticks[i+1]);
maxtriangle.push_back(sticks[i]);
return maxtriangle;
}
}
maxtriangle.push_back(-1);
}
return maxtriangle;
}
```

### Problem solution in JavaScript programming:

```function maximumPerimeterTriangle(sticks) {
let triangleVal=[];
let sorted = sticks.sort((a,b)=> a-b);

let final = [];

for(var i = 0; i < sticks.length; i++){
let a = sticks[i];
let b = sticks[i+1];
let c = sticks[i+2];

if(a + b > c && a + c > b && b + c > a){
final.push([a,b,c])
}

}

return final.length > 0 ? final[final.length-1] : [-1]
}
```

### Problem solution in Swift programming:

```func maximumPerimeterTriangle(sticks: [Int]) -> [Int] {
let sorted: [Int] = sticks.sorted().reversed()
print(sorted)
for i in 0...sorted.count - 3{
let L3 = sorted[i]
let L2 = sorted[i + 1]
let L1 = sorted[i + 2]
if L2 + L1 > L3 {
return [L1,L2,L3]
}
}
return [-1]
}
```