Unique Element Subarray Hashing

If we do j=j-1 after the while loop and apply the formual
(j-i+1)*(j-i+2)/2 why do we get different answer it should give the same answer right?

There must be differences in indexing.
Actually the formula is N (N+1)/2 where N is the length of the subarray.
If subarray begins from i and ends at j. Then N=j-i+1
If subarray begins from i and ends at j-1. Then N=j-i
Check if this is the case.

You can refer this and verify your approach https://www.geeksforgeeks.org/subarrays-distinct-elements/

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.