Can anyone please give me hint for this one.
Can anyone please give me hint for this one
hello @cbcao263
generate all subsets.
then check whether there exist any susbet with sum 0.
if it exist then true otherwise false
Is it correct?
hello @cbcao263
yeah partially correct,
a) dont add susbset sum in the last of ur vector, instead use one extra variable to hold the sum
b) ur code is considering empty subset as well , and because empty set will give 0 , ur code will return true always,
so handle that case as well
Sir, I have made this changes: -
Sir How can I control the case when subset is empty.
And Also tell When the function will return false.
simply add one more variable in ur function for maintingin thee count of elements in ur subset.
if u are adding current element in ur subset then increments its value by one.
other wise pass the same value without increment.
now in base case check for two cases.
if sum==0 and count > 0
return true
otherwise
return false
Modified Code
Sir One More Doubt
If In Base Condition
Like it will then only for one permutation and will return after that only.
I think position of return false; is wrong.
check now
Bro Have you made the changes one of return and second of odd.
I think my will work too if I add return statement while calling recursive functions or not?
And Bro it is giving wrong ans with test case.
check ->
a) there are t test cases so added while loop to run the logic for t times.
b) in place of YES and NO we have to print Yes and No
if u return the result of one function call without considering other call then it will failt for some cases .
first u need to take result of both the recursive call.
if any of them is true then return true otherwise return false.
and i have done same thing
return f() || f() ;; // it is doing same thing what i have explained above.
Ohkayy Sir
Thanks a lot for this Great Explanation.
Bro One More doubt
Which one to choose between Leetcode or Interview Bit
leetcode for practice
interview bit is a subset of leetcode.
use interviewbit for quick revision before ur placement/intership season
Okayy.
I actually liked the Question Timer feature of Leetcode.
That will actually be very helpful to solve Questions and maintain speed.
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.