Link: https://ide.codingblocks.com/s/380856
2/5 test cases are passing. Thanks in advance for your help.
Divisible Subarray
yes i did. Something is wrong in the code. Can you please look at the code for once?
P.S I tried changing all int to long long
I got the problem just help me out further.
The problem is I hadn’t considered negative cases. I don’t know the concept of negative mod n
Can you please tell me that
the negative concept is handled by making your (sum +n)%n . in this way you can handle for negative cases as well.
if you have any other doubt please let me know.
Happy Learning !!
it is still giving wrong answer.
sharing test case so you may able to analyze it easily
t=1,n=5
a[i] = -1 -3 -2 -6 -4 (1 indexed)
sum[i] = 0 -1 -4 -6 -12 -16
mod[i] = 0 0 2 0 4 0
mod[i] expected = 0 -1 -4 -1 -2 -1
My code is giving wrong mod[i] and i am using (sum+n)%n. Can you please help?
ok i’ll try again from start
@himanshugupta8 try this:
if you dint understand anything in this then you can ask here.
Happy Learning !!
shouldn’t last loop goes upto 10^5
shouldn’t last loop goes upto 10^5
because prefixSum can be greater than n
hey @himanshugupta8 the last loop should run for equal to n times as we are taking modulo with n.
so sum cannot be greater then n thats why we are running loop for n times.
because the sum can be between 0 to n only.
hey @himanshugupta8 if you feel that your doubt is cleared please markt this doubt as resolved.
Happy Learning !!
I tried multiple times but it isn’t marked as resolved.