Is there any mathematical reason to add (end-start) to answer upon getting a triplet where largest edge is smaller than sum of other two?
When nums[start] + nums[end] > nums[i] --- found a triplet (nums[start],nums[end], nums[i]) --- so why add (end-start)....Can someone help understand this?
Answer - On little thinking I realized that all numbers are sorted, start and end are two edges in the subarray
if nums[start] + nums[end] > nums[i] then all numbers between start and end-1 are > nums[i]
Numbers between start and end-1 = end-1 - start + 1 = end-start
And so taking into account all triplets x, end , i where x < end < i for all x, end-start get number of triangles in which nums[i] can be largest edge