Last Updated: 24 Sep, 2025

Counting Triangle Triplets

Easy
Asked in company
Standard Chartered

Problem statement

You are given an integer array nums representing possible side lengths. Your task is to count the number of unique triplets (i, j, k) with i < j < k that can be chosen from the array to form the sides of a valid triangle.


A triangle is considered valid if the sum of the lengths of any two sides is strictly greater than the length of the third side.


Input Format:
The first line of input contains an integer 'N', the size of the array.

The second line contains 'N' space-separated non-negative integers, representing the elements of the nums array.


Output Format:
Print a single integer representing the total number of valid triangle triplets.


Note:
The condition for three sides a, b, and c to form a triangle is a + b > c, a + c > b, and b + c > a.