human
Count the number of possible triangles | CountTriangles function.
If it is possible with a [ l ] , a [ r ] and a [ i ] then it is also possible with a [ l + 1 ] . . a [ r - 1 ] , a [ r ] and a [ i ].
checking for more possible solutions.
if not possible check for higher values of arr [ l ].
Driver Code"
How can the above be solved in Python?
 Write me a code to count the number of possible triangles and the other steps required?
assistant
#Here is code to count the number of possible triangles and the other steps required.
 def CountTriangles ( A ) :
	n = len ( A ) ;
	A . sort ( ) ;
	count = 0 ;
	for i in range ( n - 1 , 0 , - 1 ) :
		l = 0 ;
		r = i - 1 ;
		while ( l < r ) :
			if ( A [ l ] + A [ r ] > A [ i ] ) :
				count += r - l ;
				r -= 1 ;
			else :
				l += 1 ;
	print ( " No ▁ of ▁ possible ▁ solutions : ▁ " , count ) ;
if __name__ == ' _ _ main _ _ ' :
	A = [ 4 , 3 , 5 , 7 , 6 ] ;
	CountTriangles ( A ) ;