Form a Triangle
Submissions: 707   Accuracy:

24.78%

  Difficulty: Basic   Marks: 1

Given an array of integers, we need to find out all possible ways construct non-degenerate triangle using array values as its sides. If no such triangle can be formed then return 0.

Input:
The first line of input contains an integer T. Then T test cases follow. First line of each test case contains an integer N denoting the size of array. Next line of the test case contains N space seperated integers.

Output:
For each test case output a single integer containing the count of all possible triangles that can be formed using the values from the array.

Constraints:
1 <= T <= 100
1 <= N <= 104
1 <=A[i] <= 104

Example:
Input:

2
5
5 4 3 1 2
3
10 15 30

Output:
3
0

** For More Input/Output Examples Use 'Expected Output' option **

Author: harshitsidhwa


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.