1 testcase is giving wrong answer
Hi Mudit,
Your code does not work in case where the sum of all matrix is zero or sum of subset of matrix of length of matrix length - 1. For example consider the case:
input matrix: 10 9 -3 -6
output: Yes as subset [9, -3, -6] sum upto 0
where as your code print no also,
consider the case:
input matrix: -1 -1 2
output : yes as subset [-1, -1, 2] sum upto 0
where as your code print no.
I wrote the code with an arraylist containing the numbers but while debugging it i found when i return to back the arraylist still contains the value which was added to it in the previous function calling. I dont understand why it is happening as i am not returning the arraylist. Do you understand what i am trying to say?
Hi Mudit,
This is happening because when you pass an arraylist basically an address of last element in arraylist is passed ad when you add an element to an arraylist it is added permanently and hence when you return to back arraylist still contains value which was added.
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.