SUBARRAYS WITH DISTINCT ELEMENTS 2testcases failed

2 testcases failed…
logic— using hashmap and array when a distict element comes just add it in hashmap if a same element encountered then reform the hashmap by only having elemnts from last occurence of the elent to the new occurence.
and calculation length of contiguous subarrays by (l+1)(l)(l+2)/6…and summing all length and moduling at each go.

can i just know that how are you dividing by 6?
if you use simple divide, then the answer might go wrong .
therefore use modular inverse to divide .
a/b=(a*modular_inverse(b))%mod.
where, modular_inverse(b)=power(b,mod-2);

why mod-2??
and i am getting (l+1)(l)(l+2)/6 by doing summation of the series is it wrong??

yes that is wrong too.
let say we have an array A and with indexes from i to j we have all distinct elements.
Here j is the maximum of all the indexes which satisfy the condition.
than total number of subarray with distinct elements starting from i are (j-i)(j-i+1)/2;
ie let the length of the subarray be n.
all subarrays with
1 element are n.
2 element are n-1.
3 element are n-2.
.
.
.
.
n element are 1.
adding we have n
(n+1)/2

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.

please tell what if i encounter a duplicate element how to handle it?

I am unable to understand the approach pls help?