Leaderboard
Showing:
Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Form a Triangle
Basic Accuracy: 26.38% Submissions: 922 Points: 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

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Form a Triangle

Output Window