human
Ways to choose three points with distance between the most distant points <= L | .
def countTripletsLessThanL ( n , L , arr ) :.
arr = sorted ( arr ).
ways = 0.
for i in range ( n ) :.
indexGreater = upper_bound ( arr , 0 , n , arr [ i ] + L ).
.
numberOfElements = indexGreater - ( i + 1 ).
.
if ( numberOfElements >= 2 ) : ways += ( numberOfElements * ( numberOfElements - 1 ) / 2 ).
return ways.
def upper_bound ( a , low , high , element ) : while ( low < high ) : middle = int ( low + ( high - low ) / 2 ).
if ( a [ middle ] > element ) : high = middle.
else : low = middle + 1.
return low.
.
if __name__ == ' _ _ main _ _ ' : set of n points on the X axis"
Solution in Python:
 Can you provide a code to ways to choose three points with distance between the most distant points <= L and the other steps required?
assistant
#Here is code to ways to choose three points with distance between the most distant points <= L and the other steps required.
 Returns the number of triplets with the
distance between farthest points <= L
	sort the array
		find index of element greater than arr [ i ] + L
		find Number of elements between the ith
		index and indexGreater since the Numbers
		are sorted and the elements are distinct
		from the points btw these indices represent
		points within range ( a [ i ] + 1 and a [ i ] + L )
		both inclusive
		if there are at least two elements in between
		i and indexGreater find the Number of ways
		to select two points out of these
Driver Code
	arr = [ 1 , 2 , 3 , 4 ] ;
	n = len ( arr ) ;
	L = 4 ;
	ans = countTripletsLessThanL ( n , L , arr ) ;
	print ( " Total ▁ Number ▁ of ▁ ways ▁ = ▁ " , ans ) ;