HELP - MCODE - BarsAndTruck error

I got the correct answer for the sample case, but while submitting got RUNTIME error.
Can someone correct my code and write comments to point out the mistakes

I had a similar solution too and got NZEC. I am also not sure why.

hey buddy @anon56550829 sorry for replying late ,see i have not attempted that this question yet ,
but i will give it a try when ever i get time
btw the it will kind of you and helpful for me if u would explain ur thought process.

1 Like

Actually I dont know if I am correct but I think its a Knapsack problem but we have to do it multiple time to find the count of various ways the sack (truck) can be filled and also satisfy the minimum criteria.
So i used a function to make combination of number from the give list and add all the possible combos to a list.
eg: given list=[1,2,3]
list i made to store the combo - listcombo=[1,2,3,(1,2),(2,3),(1,3),(1,2,3)]
then i summed individual elements in the list and checked if its greater or equal than the required material and less than and equal to the capacity of the truck , the if it satisfy i counted it.
then finally printed count.

it gave correct ans for sample but RUNTIME for hidden

@tn6541 u will know eventually dont worry.
in coding,its important to give our best and learn by upsolving.
with that said if i could able to find any error i would convey you.

1 Like

i was getting runtime error in this problem because they have wrong inputs(improper spacings and indentations)…you might wanna try it out in c/c++ and debug accordingly

1 Like

Just answered another comment on the same question…

Man i can’t answer your query because i don’t know python but I am posting my own C++ code to help you out… The link to submission is -
and the whole idea behind is explained at - Can Someone tell me the logic for this M-Code problem…
Thanks :slight_smile:

1 Like