I am getting 2 out of 3 test case wrong answer


this is my code.
can you please why is it happening

Hi @Adi_choudhary,
Your logic is completely correct. But you also have to take mod 10^9+7 of your answer. In case the answer is 10^9+8. Your code will give answer as 10^9+8 but the correct answer will be 1.
Also use long for ans instead of int.


this i smodified code but it still not pass that teat cases.

Hey @Adi_choudhary,
I have commented the Error line (line 23) in your code. Kindly check. https://ide.codingblocks.com/s/147396
You need to take s.add(arr[j]) instead of s.add(arr[i]).

1 Like