Getting Run Error , Please Check


I think my logic is correct but I am repeatedly getting run time errors on the other questions of arrays as well.

Hey @abhinavsehgal802_270a44594b6dc4ad,
Since the constraints of the above problem are very large.
1 <= N <= 100000
1 <= t <= 20
The n^2 approach will definitely fail for this.
I ran your code and you are receiving this error for larger test cases : java.lang.OutOfMemoryError: Java heap space
As you are consuming a large amount of memory in your code.

This problem can be solved in O(n) for each testcase using the Kadane’s Algorithm.
Try using that.
Hope it helps :slight_smile:

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.