Count possible triangles
Basic Accuracy: 38.62% Submissions: 28097 Points: 1

Given an unsorted array of positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles. 

Input: 
The first line of the input contains T denoting the number of test cases. The first line of each test case contains an integer represents N and the second line contains N space-separated integers.

Output:
For each test case, print the number of possible triangles in a separate line.

Constraints:
1 <= T <= 10
3 <= N <= 103
1 <= arr[i] <= 105

Example:
Input:
2
3
3 5 4
5
6 4 9 7 8

Output:
1
10

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.

Output Window