Help me in this problem from OCT14

Problem link.

Where did I went wrong? submission here

Every help will be appreciated.

my other submissions

P.S. I tried doing this via two pointers approach and I already considered the testcase where answer could be more than range of int.
Please provide some testcase if possible.
Thanks in advance.


1 Like

@radeonguy You solution is giving wrong answer on this test case:

3 6 -6 -3 4 5 -9

Your program’s output is 22 while the correct answer is 28.

@srd091 is right. According to given examlple.


3 6 -6 -3 4 5 -9

You can use my approach that are more simpler than a two pointer.
As according to question sum of the array D is zero! That means we just simply add from left to right i.e., 3, 3+6, 3 + 6 + (-3)…

So we will obtain a series like this 3, 9, 3, 0, 4, 9, 0

But we have to complete the tour to every dinasour so we have to add them all to get the final answer! i.e., 3 + 9 + 3 + 0 + 4 + 9 + 0 = 28;

Click Here to know more.

Thank you brother you are such a life saver!
This problem messed with my mind for hours. Your testcase helped a lot.

1 Like

Your technique is also good. But I made a little change and it was good enough get AC.
Thanks for your time though :smiley:

Just chill buddy! I also learned a new concept from this intriguing question!

1 Like