Problem in coading


check my code I think logic is correct


this should be val[n-1]

also
if(n==-1){
return -1;
}
this is not correct instead here you can return some large value like 10000

1 test case not pass and if n==-1 why we return very large value


1 test case not pass and
explain the logic behind if n==-1 why we return very large value

plzz reply sir and explain logic

n==-1 only if you are not able to find any item so money needed should be max

also
see here you are taking min

so if you return -1 then -1 will be min every time so ans will be -1

i hope you understand now

and sir one test case didn’t pass

sir plz reply and clear my doubt

your code shows wrong output for this input
5 6
175 155 181 179 41 204

correct output is 204

sir plzz correct it
why it showing wrong output

in base correct condition will be

 if(W<=0){
        return 0;
    }

i think doubt clear now :grinning:
so please mark it as resolved