Subarray With Distinct Element

how we come to know that sum of subarray lenght=((j-i+1)*(j-i+2))/2;

for an array of having all distinct elements this formula holds true
for example:
arr[] = {1,2,3}
from 1(i = 0) to 3(j = 2) it forms 3 subarray of distinct elements
{1,2,3} , {1,2} , {1}
so Sum = 3 +2 +1 = 6 (((2-0+1)*(2-0+2)/2) = 6)
now
for {2, 3}
{2, 3}, {2}
Sum = 6 + 2 +1
for {3}
Sum = 9 +1 = 10
Hence Proved :smile:

Hey @RULEREMPIRES
You got it