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.
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;