{"id":"1cabdb32-4bfc-4262-8be9-d0be621f4b7e","name":"Count Possible Triangles","description":"Given an unsorted array arr[] of n positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles. \r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"3 &lt;= n &lt;= 10^3\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint no_of_t(vector<int> &arr)\n{\n \nreturn 0;\n}\nint main()\n{\n int n;\n cin>>n;\n vector<int> arr(n);\n \n for (int j = 0; j < n; j++) {\n cin>>arr[j];\n }\n\n int x=no_of_t(arr);\n cout<<x;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int countTriangles(int[]arr) {\r\n //write your code here\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(countTriangles(arr));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"5\r\n6 4 9 7 8","sampleOutput":"10","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"dbf515bd-cc4d-473d-99f3-d9bb508d04f1","name":"Count Possible Triangles","slug":"count-possible-triangles","type":1}],"next":{"id":"a0272830-a1ce-4ebd-aaee-82b7f71b2f0e","name":"Count Possible Triangles","type":3,"slug":"count-possible-triangles"},"prev":{"id":"2c674444-e65d-427d-8cb3-d1df12da48ac","name":"Count zeros in a sorted arrays MCQ","type":0,"slug":"count-zeros-in-a-sorted-arrays-mcq"}}}

Count Possible Triangles

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

{"id":"1cabdb32-4bfc-4262-8be9-d0be621f4b7e","name":"Count Possible Triangles","description":"Given an unsorted array arr[] of n positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles. \r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"3 &lt;= n &lt;= 10^3\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint no_of_t(vector<int> &arr)\n{\n \nreturn 0;\n}\nint main()\n{\n int n;\n cin>>n;\n vector<int> arr(n);\n \n for (int j = 0; j < n; j++) {\n cin>>arr[j];\n }\n\n int x=no_of_t(arr);\n cout<<x;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int countTriangles(int[]arr) {\r\n //write your code here\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(countTriangles(arr));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"5\r\n6 4 9 7 8","sampleOutput":"10","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"dbf515bd-cc4d-473d-99f3-d9bb508d04f1","name":"Count Possible Triangles","slug":"count-possible-triangles","type":1}],"next":{"id":"a0272830-a1ce-4ebd-aaee-82b7f71b2f0e","name":"Count Possible Triangles","type":3,"slug":"count-possible-triangles"},"prev":{"id":"2c674444-e65d-427d-8cb3-d1df12da48ac","name":"Count zeros in a sorted arrays MCQ","type":0,"slug":"count-zeros-in-a-sorted-arrays-mcq"}}}
plane

Editor


Loading...

Count Possible Triangles

easy

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

Constraints

3 <= n <= 10^3 1 <= arr[i] <= 10^3

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

5 6 4 9 7 8

Sample Output

10

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode