Two failed test cases

Hello @sufia.aleena12, pls see the testcase
3
1 2 1
Check this case your ans is coming as 1.888889 but the actual ans is 1.666667
In case you don’t get your mistake pls let me know I will help you out further.

I still didn’t get my mistake

        ans[i]=ans[i-1]+(i-lastocc[i]);
        lastocc[a[i]]=i;
        sum+=ans[i];

you have written this inside the loop but we need to write lastocc[a[i]] instead of lastocc[i] so pls make this correct your code will work fine.

        ans[i]=ans[i-1]+(i-lastocc[a[i]]);
        lastocc[a[i]]=i;
        sum+=ans[i];

Yes, it worked!!
Thank you

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.