Can anyone explain the quetion clearly .
I DIDNOT GET THE QUESTION
hello @epic007
In this question a 1-indexed (indexing starts from 1) array is given. Now you choose two values l and r between 1 to n (both inclusive) where l has to be smaller than r ( l is left index r is right index). If l > r swap l and r. Now once you have chosen l and r you have to tell the expected value of number of unique elements in the array segment between l and r.
can u explain it with an exapmle
2
1 2
and answer is 1.50000
Here we need to choose and l and any r from 1 to n
And for every possible l,r if(l > r) then swap them you need to find the distinct nos. in that subarray
So
1
1 2
2 are the subarrays
if l = 1 and r = 1
1 no. of distinct nos. = 1
if l = 1 and r = 2
1 2 no. of distinct nos. = 2
if l = 2 and r = 1
1 2 no. of distinct nos. = 2
if l = 2 and r = 2
2 no. of distinct nos. = 1
So if we sum all the distinct nos. of all the subarrays then it will be 1 + 2 + 2 + 1 = 6
and then divide by 4 as in total we have 4 cases. (we have n^2 cases in total ) n values for l and n values for r
So, 6/4 = 1.5000
What is the answer for 1 2 3 4? explanation