In our code for max value as 1, we are checking 2 conditions (positive values and zero occurrence).
if array doesn’t have a positive value but it encounters a 0, we are returning 0 as our answer.
This logic will fail for the test case [-1,-1,0].
In our code for max value as 1, we are checking 2 conditions (positive values and zero occurrence).
if array doesn’t have a positive value but it encounters a 0, we are returning 0 as our answer.
This logic will fail for the test case [-1,-1,0].
LeetCode evaluated all the corner test cases, since his code gave a Accepted
the logic is correct please try to dry run the code using this array
in case u still stuck up somewhere please ping back
Hi Chhavi,
I did it and explained the same in my doubt.
With our code, the output for [-1,-1,0] would be 0 but the expected output should be 1.
I know it is getting accepted on Leetcode but with this test case it will not give the expected output.
For the same, I think there should be hasNegative var that will store the count of -ve values in the array and when max =1, we will check 3 conditions :
@PThak2018
I see that this code does not gives a accepted in Leetcode
i coded this and tried to submit it failed to simple case when the array is just [-2]
this code gives answer 1 insteead it should be -2
also the case u talked of is not giving correct answer
i dont know how sir`s code got accepted
i`ll get the video updated…
Handle the case when arr.length==1… return arr[0]. It will give u correct answer for [-2].
But for the test case stated earlier, solution needs to be updated.
i have asked the person in charge to get it updated
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.
are the solutions updated or more test cases are added to the problem?
its in the process of getting updated.