Geeksforgeeks

Timer is Running

Given an Array of non-negative integers. Find out the maximum perimeter of the triangle from the array.

**Input:**

The first line contains an integer **T,** the number of test cases. For each test case, the first line contains an integer **n, **the size of the array. Next line contains n- space separated integers.

**Output:**

For each test case, the output is an integer displaying the maximum perimeter if the triangle is possible else print **-1.**

**Constraints:**

1 <= T <= 100

3 <= n <= 100

1 <= a[] <=100

**Example:
Input**

2

6

6 1 6 5 8 4

7

7 55 20 1 4 33 12

20

-1

**Explanation:
1. **Triangle formed by 8,6 & 6. Thus perimeter 20.

Author: vanshi_14

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

jainshubham52535 | 529 |

Pathak1899 | 436 |

yashdip123 | 380 |

kirtidee18 | 377 |

jots62 | 351 |

kirtidee18 | 1057 |

ykaushik | 752 |

aggarwalvatsal5 | 741 |

harbilassingh | 576 |

pmr_3689 | 570 |

blackshadows | 5456 |

Ibrahim Nash | 5450 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4827 |

Login to report an issue on this page.